# YouTube

> YouTube channels through your Google Cloud project, with the single `youtube.force-ssl` scope.

The permissions each operation needs are in [App Review: YouTube](https://docs.koil.co/app-review#youtube).

-   YouTube has no Shorts flag: it makes any square or vertical upload of up to three minutes a Short, so publishing takes no Shorts option, and reads report `durationSeconds` and `aspectRatio` for telling the two apart.
-   YouTube publishes no comment webhooks, so uploads and comments are collected by polling against your project's daily quota; a spent quota answers `platform_rate_limit` with `Retry-After` set to Google's midnight-Pacific reset.
-   Uploads from a project that has not passed Google's compliance audit are made private by YouTube, whatever `privacyStatus` you asked for.
-   Livestreams and live chat are not a surface yet.

| Collection | Operations | Events | Backfill |
| --- | --- | --- | --- |
| [`youtube.videos.posts`](https://docs.koil.co/platforms/youtube#youtube.videos.posts) | `list`, `get`, `publish`, `update`, `perform_action`, `delete` | `created` | yes |
| [`youtube.videos.comments`](https://docs.koil.co/platforms/youtube#youtube.videos.comments) | `list`, `get`, `publish`, `update`, `perform_action`, `delete` | `created` | yes |

## `youtube.videos.posts`

The channel's uploads, videos and Shorts alike.

### `list`

List the channel's videos and Shorts, newest first.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `cursor` | `string` | no | Opaque cursor for fetching the next result page. |
| `limit` | `integer` | no | Maximum number of items to return. |
| `includePlatformRaw` | `boolean` | no | Whether to include transient platform-native payloads. |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "cursor": {
      "type": "string",
      "description": "Opaque cursor for fetching the next result page.",
      "minLength": 1
    },
    "limit": {
      "type": "integer",
      "description": "Maximum number of items to return.",
      "minimum": 1,
      "maximum": 100
    },
    "includePlatformRaw": {
      "type": "boolean",
      "description": "Whether to include transient platform-native payloads."
    }
  },
  "additionalProperties": false
}
```

### `get`

Get one YouTube video by platform id.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |
| `includePlatformRaw` | `boolean` | no | Whether to include transient platform-native payloads. |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    },
    "includePlatformRaw": {
      "type": "boolean",
      "description": "Whether to include transient platform-native payloads."
    }
  },
  "additionalProperties": false
}
```

### `publish`

Upload a YouTube video or Short through the resumable upload protocol.

Submit through `POST /v1/publish-requests` with `collection: "youtube.videos.posts"`. These fields go in the item's `args`; `profileId` and `variant` are item fields.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | `string` | yes | Up to 100 characters; YouTube refuses < and >. |
| `text` | `string` | no | Description, up to 5,000 bytes; YouTube refuses < and >. |
| `tags` | `string[]` | no | Keyword tags; at most 500 characters in total. |
| `categoryId` | `string` | no | A YouTube video category id, e.g. 22 for People & Blogs. |
| `privacyStatus` | `"public" \| "private" \| "unlisted"` | yes | Who can see the video. |
| `scheduledPublishAt` | `string (date-time)` | no | When YouTube makes the uploaded video public; requires privacyStatus private. The upload itself runs now, or at the item's `scheduledAt`, which delays the whole publish instead. |
| `madeForKids` | `boolean` | no | The self-declared audience setting YouTube requires an answer for. |
| `aiGenerated` | `boolean` | no | Label the post as AI-generated, with the platform's own AI label. |
| `paidPartnership` | `boolean` | no | Label the post as a paid partnership with a brand. |
| `notifySubscribers` | `boolean` | no | Whether YouTube notifies subscribers; defaults to true. |
| `media` | `object \| object[]` | yes |  |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "title",
    "privacyStatus",
    "media"
  ],
  "properties": {
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[^<>]*$",
      "description": "Up to 100 characters; YouTube refuses < and >."
    },
    "text": {
      "type": "string",
      "maxLength": 5000,
      "pattern": "^[^<>]*$",
      "description": "Description, up to 5,000 bytes; YouTube refuses < and >."
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "Keyword tags; at most 500 characters in total."
    },
    "categoryId": {
      "type": "string",
      "minLength": 1,
      "description": "A YouTube video category id, e.g. 22 for People & Blogs."
    },
    "privacyStatus": {
      "enum": [
        "public",
        "private",
        "unlisted"
      ],
      "description": "Who can see the video."
    },
    "scheduledPublishAt": {
      "type": "string",
      "format": "date-time",
      "description": "When YouTube makes the uploaded video public; requires privacyStatus private. The upload itself runs now, or at the item's `scheduledAt`, which delays the whole publish instead."
    },
    "madeForKids": {
      "type": "boolean",
      "description": "The self-declared audience setting YouTube requires an answer for."
    },
    "aiGenerated": {
      "type": "boolean",
      "description": "Label the post as AI-generated, with the platform's own AI label."
    },
    "paidPartnership": {
      "type": "boolean",
      "description": "Label the post as a paid partnership with a brand."
    },
    "notifySubscribers": {
      "type": "boolean",
      "description": "Whether YouTube notifies subscribers; defaults to true."
    },
    "media": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "object",
            "required": [
              "mediaId"
            ],
            "properties": {
              "mediaId": {
                "type": "string",
                "minLength": 1
              },
              "contentType": {
                "type": "string",
                "minLength": 1,
                "pattern": "^video/"
              },
              "altText": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          },
          {
            "type": "object",
            "required": [
              "sourceUrl"
            ],
            "properties": {
              "sourceUrl": {
                "type": "string",
                "minLength": 1
              },
              "contentType": {
                "type": "string",
                "minLength": 1,
                "pattern": "^video/"
              },
              "altText": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        ]
      },
      "minItems": 1,
      "maxItems": 1
    }
  },
  "additionalProperties": false
}
```

#### Media requirements

An asset that meets everything under _Copied as is_ is published exactly as uploaded. Otherwise Koil converts only what misses, a billed media add-on that needs a paid plan. Anything under _Refused_ fails the publish request, since no conversion fixes it.

| Media | Copied as is | Otherwise converted | Refused |
| --- | --- | --- | --- |
| Video | MP4/MOV or MKV/WebM, H.264, HEVC, VP8, VP9, AV1, ProRes, DNxHD/DNxHR, CineForm, MPEG-4 Part 2 or MPEG-2 | re-encoded to H.264 in MP4 | longer than 12 h; over 256 GB once staged |

### `update`

Edit a video's title, description, tags, category, or privacy.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |
| `title` | `string` | no |  |
| `text` | `string` | no |  |
| `tags` | `string[]` | no |  |
| `categoryId` | `string` | no |  |
| `privacyStatus` | `"public" \| "private" \| "unlisted"` | no | Who can see the video. |
| `includePlatformRaw` | `boolean` | no | Whether to include transient platform-native payloads. |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[^<>]*$"
    },
    "text": {
      "type": "string",
      "maxLength": 5000,
      "pattern": "^[^<>]*$"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "categoryId": {
      "type": "string",
      "minLength": 1
    },
    "privacyStatus": {
      "enum": [
        "public",
        "private",
        "unlisted"
      ],
      "description": "Who can see the video."
    },
    "includePlatformRaw": {
      "type": "boolean",
      "description": "Whether to include transient platform-native payloads."
    }
  },
  "additionalProperties": false
}
```

### `perform_action`

Like a video as the channel, or remove the channel's like. Answers with the action applied.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |
| `action` | `"like" \| "unlike"` | yes | What to do with the item: `like` (like it as the profile), `unlike` (remove the profile's like). |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId",
    "action"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    },
    "action": {
      "enum": [
        "like",
        "unlike"
      ],
      "description": "What to do with the item: `like` (like it as the profile), `unlike` (remove the profile's like).",
      "x-koil-narrows": "ContentAction"
    }
  },
  "additionalProperties": false
}
```

### `delete`

Delete one of the channel's videos.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    }
  },
  "additionalProperties": false
}
```

### Not offered

-   `resolve_attachment`: not applicable

### Events

-   [`content.youtube.videos.posts.created`](https://docs.koil.co/events#content.youtube.videos.posts.created)

Backfill: supported (bounded coverage); see [Backfill history](https://docs.koil.co/guides/backfill).

Item schema

What `list` and `get` return and what events carry as `data`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `references` | `object[]` | no |  |
| `text` | `string` | no | Caption/body text for content. |
| `media` | `object[]` | no |  |
| `engagement` | `object` | no | Platform-reported engagement counts. |
| `permalink` | `string (uri)` | no | The thing's URL on the platform, for display and linking only, never as a key. It may point at something private or expired. |
| `publishedAt` | `string (date-time)` | no | When the platform published it. |
| `externalId` | `string` | yes | Platform-owned content identifier. |
| `title` | `string` | yes |  |
| `tags` | `string[]` | no |  |
| `privacyStatus` | `"public" \| "private" \| "unlisted" \| "other"` | no | Who can see the video. `other` is a setting YouTube added that Koil does not model yet. |
| `aspectRatio` | `number` | no |  |
| `uploadStatus` | `"uploaded" \| "processed" \| "failed" \| "rejected" \| "deleted" \| "other"` | no | `uploaded` until YouTube has processed the file, then `processed`; `failed`, `rejected`, or `deleted` otherwise. `other` is a state YouTube added that Koil does not model yet. |
| `liveBroadcast` | `"none" \| "live" \| "upcoming" \| "other"` | no | `live` or `upcoming` while the video is a broadcast; `none` for an ordinary upload. |
| `madeForKids` | `boolean` | no |  |
| `durationSeconds` | `number` | no |  |
| `scheduledPublishAt` | `string (date-time)` | no | When a private video is scheduled to go public. |
| `platformRaw` | `unknown` | no | Optional platform-native payload included only for transient delivery/debug use. |
| `kind` | `"youtube.videos.posts"` | yes | The collection that delivered this item. |

## `youtube.videos.comments`

Comments on the channel's videos, and replies to them.

### `list`

List comments across the channel's videos (newest thread first, replies inline), one video's comments, or the replies to one comment.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `containerId` | `string` | no | Only this video's comments; every video of the channel otherwise. |
| `targetId` | `string` | no | The replies to this top-level comment instead of the threads. |
| `moderationStatus` | `"published" \| "held_for_review" \| "likely_spam"` | no | Which of YouTube's queues to read; defaults to published. Ignored with targetId. |
| `searchTerms` | `string` | no | Only threads containing these terms. Ignored with targetId. |
| `cursor` | `string` | no | Opaque cursor for fetching the next result page. |
| `limit` | `integer` | no | Maximum number of items to return. |
| `includePlatformRaw` | `boolean` | no | Whether to include transient platform-native payloads. |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "containerId": {
      "type": "string",
      "minLength": 1,
      "description": "Only this video's comments; every video of the channel otherwise."
    },
    "targetId": {
      "type": "string",
      "minLength": 1,
      "description": "The replies to this top-level comment instead of the threads."
    },
    "moderationStatus": {
      "enum": [
        "published",
        "held_for_review",
        "likely_spam"
      ],
      "description": "Which of YouTube's queues to read; defaults to published. Ignored with targetId."
    },
    "searchTerms": {
      "type": "string",
      "minLength": 1,
      "description": "Only threads containing these terms. Ignored with targetId."
    },
    "cursor": {
      "type": "string",
      "description": "Opaque cursor for fetching the next result page.",
      "minLength": 1
    },
    "limit": {
      "type": "integer",
      "description": "Maximum number of items to return.",
      "minimum": 1,
      "maximum": 100
    },
    "includePlatformRaw": {
      "type": "boolean",
      "description": "Whether to include transient platform-native payloads."
    }
  },
  "additionalProperties": false
}
```

### `get`

Get one YouTube comment by platform id.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |
| `includePlatformRaw` | `boolean` | no | Whether to include transient platform-native payloads. |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    },
    "includePlatformRaw": {
      "type": "boolean",
      "description": "Whether to include transient platform-native payloads."
    }
  },
  "additionalProperties": false
}
```

### `publish`

Publish a YouTube comment: a top-level comment on a video, or a reply to a top-level comment.

Submit through `POST /v1/publish-requests` with `collection: "youtube.videos.comments"`. These fields go in the item's `args`; `profileId` and `variant` are item fields.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `target` | `object` | yes | One thing on the platform outside this item: content, an account, or anything else the platform gives an id or a URL. |
| `text` | `string` | yes | Comment text as the author wrote it. |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "target",
    "text"
  ],
  "properties": {
    "target": {
      "type": "object",
      "required": [
        "kind",
        "externalId"
      ],
      "properties": {
        "kind": {
          "enum": [
            "youtube.videos.comments",
            "youtube.videos.posts"
          ]
        },
        "externalId": {
          "type": "string",
          "description": "Platform-owned content identifier.",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "description": "One thing on the platform outside this item: content, an account, or anything else the platform gives an id or a URL."
    },
    "text": {
      "type": "string",
      "description": "Comment text as the author wrote it.",
      "minLength": 1,
      "maxLength": 10000
    }
  },
  "additionalProperties": false
}
```

### `update`

Edit the text of a comment the channel made.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |
| `text` | `string` | yes | Comment text as the author wrote it. |
| `includePlatformRaw` | `boolean` | no | Whether to include transient platform-native payloads. |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId",
    "text"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    },
    "text": {
      "type": "string",
      "description": "Comment text as the author wrote it.",
      "minLength": 1,
      "maxLength": 10000
    },
    "includePlatformRaw": {
      "type": "boolean",
      "description": "Whether to include transient platform-native payloads."
    }
  },
  "additionalProperties": false
}
```

### `perform_action`

Publish, hold for review, or reject a comment on one of the channel's videos, optionally banning its author. Answers with the status applied rather than the comment: YouTube's read by id never reports `moderationStatus`, and no read returns a rejected comment.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |
| `action` | `"approve" \| "hold" \| "reject" \| "ban_author"` | yes | What to do with the item: `approve` (publish it, clearing a hold or rejection), `hold` (hold it for review), `reject` (reject it, removing it from public view), `ban_author` (reject it and block its author from the profile). |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId",
    "action"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    },
    "action": {
      "enum": [
        "approve",
        "hold",
        "reject",
        "ban_author"
      ],
      "description": "What to do with the item: `approve` (publish it, clearing a hold or rejection), `hold` (hold it for review), `reject` (reject it, removing it from public view), `ban_author` (reject it and block its author from the profile).",
      "x-koil-narrows": "ContentAction"
    }
  },
  "additionalProperties": false
}
```

### `delete`

Delete a comment on one of the channel's videos.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `profileId` | `string` | yes | Koil Profile associated with the operation. |
| `externalId` | `string` | yes |  |

JSON Schema

```json
{
  "type": "object",
  "required": [
    "profileId",
    "externalId"
  ],
  "properties": {
    "profileId": {
      "type": "string",
      "description": "Koil Profile associated with the operation.",
      "minLength": 1
    },
    "externalId": {
      "type": "string",
      "minLength": 1
    }
  },
  "additionalProperties": false
}
```

### Not offered

-   `resolve_attachment`: not applicable

### Events

-   [`content.youtube.videos.comments.created`](https://docs.koil.co/events#content.youtube.videos.comments.created)

Backfill: supported (bounded coverage); see [Backfill history](https://docs.koil.co/guides/backfill).

Item schema

What `list` and `get` return and what events carry as `data`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `containerId` | `string` | no | The place the item was published into and lives in: the post or video a comment is on, or the conversation a message is in. Every item in the same place has the same `containerId`, replies to replies included. A post in the account has none. |
| `target` | `object` | yes | The one thing on the platform this item directly responds to: a comment's post, or the comment it replies to; a message's quoted or replied-to message, story or comment; what a reaction reacts to. Absent when the platform reports nothing it responds to. |
| `references` | `object[]` | no |  |
| `text` | `string` | no | Caption/body text for content. |
| `author` | `object` | no | Platform actor reference for observed content. |
| `ownerAuthored` | `boolean` | no | Whether the Profile's own account wrote it. Absent when Koil cannot tell, which does not mean someone else did. |
| `attachments` | `unknown \| unknown \| unknown[]` | no |  |
| `hidden` | `boolean` | no | Whether the account hid the comment from the public. Absent when the platform did not say. |
| `engagement` | `object` | no | Platform-reported engagement counts. |
| `permalink` | `string (uri)` | no | The thing's URL on the platform, for display and linking only, never as a key. It may point at something private or expired. |
| `publishedAt` | `string (date-time)` | no | When the platform published it. |
| `updatedAt` | `string (date-time)` | no | When the platform last updated it. |
| `externalId` | `string` | yes | Platform-owned content identifier. |
| `moderationStatus` | `"published" \| "held_for_review" \| "likely_spam" \| "rejected" \| "other"` | no | YouTube's moderation state of a comment. `other` is a state YouTube added that Koil does not model yet. |
| `platformRaw` | `unknown` | no | Optional platform-native payload included only for transient delivery/debug use. |
| `kind` | `"youtube.videos.comments"` | yes | The collection that delivered this item. |
