# Publishing

ShortGenius lets you publish your videos automatically to various platforms (TikTok, YouTube, X, etc.). This section covers how to manage these connections and how to utilize them in your video creation workflow.

***

## Listing Publishing Destinations

**Endpoint**: `GET /connections`

This endpoint returns all the publishing destinations (a.k.a. "connections") you've set up in your ShortGenius account. Examples include TikTok, YouTube, X, and Email.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { ShortGenius } from 'shortgenius'

const client = new ShortGenius({
  bearerAuth: 'YOUR_API_TOKEN'
})

const connections = await client.getConnections()

console.log(`Found ${connections.length} connections:`)
for (const connection of connections) {
  console.log(`- ${connection.name} (${connection.type}): ${connection.id}`)
}
```

{% endtab %}

{% tab title="Python" %}

```python
from shortgenius import Shortgenius

client = Shortgenius(api_key="YOUR_API_TOKEN")

connections = client.connections.list()

print(f"Found {len(connections)} connections:")
for connection in connections:
    print(f"- {connection.name} ({connection.type}): {connection.id}")
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request GET \
  --url "https://shortgenius.com/api/v1/connections" \
  --header "Authorization: Bearer YOUR_API_TOKEN"
```

{% endtab %}
{% endtabs %}

**Sample Response**:

```json
[
  {
    "id": "95c87129-3e78-49ee-8305-d7bd5201263a",
    "type": "TikTok",
    "name": "My TikTok Account"
  },
  {
    "id": "00d10d95-b58c-4a60-9cae-578490ab5201",
    "type": "YouTube",
    "name": "My YouTube Channel"
  },
  {
    "id": "9830b2d9-76f7-4471-b5f6-a33041555c75",
    "type": "X",
    "name": "My Twitter/X Profile"
  }
]
```

### Response Fields

| Field  | Description                                                                                    |
| ------ | ---------------------------------------------------------------------------------------------- |
| `id`   | Unique ID for this connection. You'll pass this to **/videos** or **/series** when publishing. |
| `type` | The platform type (e.g., `"TikTok"`, `"YouTube"`, `"X"`, `"Email"`).                           |
| `name` | A user-friendly name for your reference.                                                       |

***

## Using Connections in Video Creation

When creating or scheduling videos and series, you can specify which connection(s) to publish to.

For example, in **`POST /videos`**:

{% tabs %}
{% tab title="TypeScript" %}

```typescript
// Get your connections first
const connections = await client.getConnections()
const tiktokConnection = connections.find(c => c.type === 'TikTok')

// Create a video with publishing
const video = await client.createVideo({
  connectionIds: [tiktokConnection.id],
  title: 'Fun AI Video',
  caption: 'Check out this AI-created content!',
  contentType: 'Custom',
  locale: 'en-US',
  scenes: draft.scenes, // from your draft
  voiceId: voice.id,
  aspectRatio: '9:16' // 9:16 for TikTok
})

console.log(`Video will be published to ${tiktokConnection.name}`)
```

{% endtab %}

{% tab title="Python" %}

```python
# Get your connections first
connections = client.connections.list()
tiktok_connection = next((c for c in connections if c.type == "TikTok"), None)

# Create a video with publishing
video = client.videos.create(
    connection_ids=[tiktok_connection.id],
    title="Fun AI Video",
    caption="Check out this AI-created content!",
    content_type="Custom",
    locale="en-US",
    scenes=draft.scenes,  # from your draft
    voice_id=voice.id,
    aspect_ratio="916"  # 9:16 for TikTok
)

print(f"Video will be published to {tiktok_connection.name}")
```

{% endtab %}

{% tab title="JSON Structure" %}

```json
{
  "connection_ids": [
    "95c87129-3e78-49ee-8305-d7bd5201263a"
  ],
  "title": "Fun AI Video",
  "caption": "Check out this AI-created content!",
  ...
}
```

{% endtab %}
{% endtabs %}

ShortGenius will automatically publish the generated video to the specified platform once it finishes rendering (and according to any `publish_at` scheduling you set).

### Scheduling Videos

If you use the `publish_at` field in your `POST /videos` body, ShortGenius will **delay** the publish time until your desired date/time (in ISO 8601 format). For example:

{% tabs %}
{% tab title="TypeScript" %}

```typescript
const scheduledDate = new Date()
scheduledDate.setDate(scheduledDate.getDate() + 7) // 1 week from now

const video = await client.createVideo({
  // ... other fields ...
  publishAt: scheduledDate.toISOString()
})

console.log(`Video scheduled for ${scheduledDate.toLocaleString()}`)
```

{% endtab %}

{% tab title="Python" %}

```python
from datetime import datetime, timedelta

scheduled_date = datetime.now() + timedelta(days=7)  # 1 week from now

video = client.videos.create(
    # ... other fields ...
    publish_at=scheduled_date.isoformat() + "Z"
)

print(f"Video scheduled for {scheduled_date}")
```

{% endtab %}

{% tab title="JSON" %}

```json
"publish_at": "2025-06-01T10:00:00Z"
```

{% endtab %}
{% endtabs %}

When that time arrives, ShortGenius begins publishing to your designated connections (e.g., TikTok, YouTube, etc.).

***

## Using Connections in Series

Similarly, for **`POST /series`**, include an array of `connection_ids` to apply an automated schedule across multiple episodes:

{% tabs %}
{% tab title="TypeScript" %}

```typescript
const connections = await client.getConnections()
const youtubeConnection = connections.find(c => c.type === 'YouTube')
const xConnection = connections.find(c => c.type === 'X')

const series = await client.createSeries({
  connection_ids: [youtubeConnection.id, xConnection.id],
  aspect_ratio: '9:16',
  locale: 'en-US',
  content_type: 'Custom',
  topics: [{ topic: 'AI Basics: What is Machine Learning?' }, { topic: 'AI Basics: Neural Networks Explained' }],
  schedule: {
    timeZone: 'America/Denver',
    times: [
      { dayOfWeek: 2, timeOfDay: 900 } // Tuesday at 9:00 AM
    ]
  }
})

console.log(`Series will publish to ${[youtubeConnection.name, xConnection.name].join(' and ')}`)
```

{% endtab %}

{% tab title="Python" %}

```python
connections = client.connections.list()
youtube_connection = next((c for c in connections if c.type == "YouTube"), None)
x_connection = next((c for c in connections if c.type == "X"), None)

series = client.series.create(
    connection_ids=[youtube_connection.id, x_connection.id],
    aspect_ratio="9:16",
    locale="en-US",
    content_type="Custom",
    topics=[
        {"topic": "AI Basics: What is Machine Learning?"},
        {"topic": "AI Basics: Neural Networks Explained"}
    ],
    schedule={
        "timeZone": "America/Denver",
        "times": [
            {"dayOfWeek": 2, "timeOfDay": 900}  # Tuesday at 9:00 AM
        ]
    }
)

print(f"Series will publish to {youtube_connection.name} and {x_connection.name}")
```

{% endtab %}

{% tab title="cURL" %}

```json
{
  "connection_ids": [
    "00d10d95-b58c-4a60-9cae-578490ab5201",
    "9830b2d9-76f7-4471-b5f6-a33041555c75"
  ],
  "aspect_ratio": "9:16",
  "locale": "en-US",
  "schedule": {
    "timeZone": "America/Denver",
    "times": [
      { "dayOfWeek": 2, "timeOfDay": 900 }
    ]
  },
  ...
}
```

{% endtab %}
{% endtabs %}

Each video in that series will automatically publish to the selected platforms at the scheduled times.

***

## Publishing State

ShortGenius tracks the **publishing\_state** of each video:

* **`pending`** – Video is waiting to be processed or published.
* **`processing`** – Video is being rendered or is about to be uploaded.
* **`completed`** – Successfully published.
* **`skipped`** – Publishing skipped for some reason (e.g., missing credentials).
* **`error`** – An error occurred during publishing.

You can view this state in the response from:

* **`GET /videos`**
* **`GET /videos/{id}`**
* **`GET /series/{id}`** (for each episode)

***

## Troubleshooting Publishing

If publishing fails:

1. Check your connection credentials on the ShortGenius **dashboard**.
2. Ensure your publishing time (`publish_at`) is not in the past.
3. Review the error in the video's `publishing_state`. If you see `"error"`, there may be a message in the response body (such as missing permissions).

***

## Next Steps

Now that you can publish and schedule your AI-generated videos, you might want to keep an eye on your usage and credits. Head over to the [Usage & Credits](https://shortgenius.gitbook.io/api/guides/publishing) section to learn how to manage resources effectively.
