# Content

> How platform content is named and related — collections, kind, containers, targets, references, and pointers — and how it is created and changed.

Every post, comment, message, or other item Koil delivers follows its collection's schema, and the same few fields say what it is, where it lives, and what it relates to. This reply to an Instagram comment is the `data` of a `content.instagram.media.comments.created` event, and the same shape a read of it returns:

```json
{
  "kind": "instagram.media.comments",
  "externalId": "17870913679156914",
  "containerId": "17895695668004550",
  "target": {
    "kind": "instagram.media.comments",
    "externalId": "17858893269000001"
  },
  "text": "Is the June date still open?",
  "author": {
    "externalId": "17841453018326712",
    "username": "sana.travels"
  },
  "ownerAuthored": false
}
```

-   `kind` is the collection that delivered it.
-   `externalId` is Instagram's id for the reply.
-   `containerId` is the post it is on.
-   `target` is the comment it replies to.

## Collections

A collection is one platform feed: the items a platform serves through one set of reads, writes, and events. It is named `{platform}.{surface}.{resource}`, such as `instagram.media.comments` ([Platforms](https://docs.koil.co/platforms#naming) explains the parts), and the one name routes everything about it:

-   **Content routes:** `/v1/profiles/{profileId}/content/{collection}` and `/v1/profiles/{profileId}/content/{collection}/{externalId}`, under the Profile the item is read and changed through.
-   **Requests:** the `collection` of a publish or backfill request.
-   **Events:** the topic `content.{collection}.{action}`, and `collection` in a content event's `context`.
-   **Payloads:** every item's `kind`.

Not every collection is posts and comments: `whatsapp.dm.statuses` delivers message delivery statuses, and `instagram.dm.conversations`, `facebook.dm.conversations` and `tiktok.dm.conversations` conversations, and `whatsapp.groups.conversations` WhatsApp groups, each keyed by the `containerId` its messages carry. A collection is a feed, not a place on the platform; where an item lives is its [container](https://docs.koil.co/concepts/content#containers).

## Kind and externalId

Every payload says what it is in `kind`. A Koil resource's `kind` is its snake\_case name (`profile`); a content item's is the collection that delivered it. Dotted collection names never collide with resource names, so one switch on `data.kind` routes every event you receive. Ids split the same way: a Koil resource's own id is `id`, a content item's the platform's `externalId`.

`externalId` is the platform's own id for the item. One item can arrive through more than one collection (a mention record is the mentioning post or comment itself), and Koil delivers each feed as the platform sends it without merging them. `kind` then differs, since it names the feed's schema rather than the item, but `externalId` is the same in every collection, so dedupe on it. LinkedIn is the exception: it spells one comment's id two ways, so join LinkedIn comments on `commentNumericId`, the part both spellings share.

## Containers

`containerId` is 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, on reads and events alike, so group a thread or an inbox by it. List routes take it: a post's comments and a conversation's messages are listed by `containerId`.

A conversation's `containerId` is whatever the platform can always name:

-   **TikTok:** the conversation id.
-   **Instagram, Facebook, and WhatsApp:** the counterpart's own id, since Meta's messaging webhooks carry no conversation id. On WhatsApp that is the person's business-scoped user id.
-   **WhatsApp groups:** a group chat is its own collection, `whatsapp.groups.messages`, and its `containerId` is the group's id.

On LinkedIn, a comment's `containerId` is its post's share or ugcPost URN. LinkedIn also names posts by an activity URN that it never maps to the share URN, so `containerId` is absent where LinkedIn sent only that, as on a notification it did not decorate.

An item that lives on the account itself has none: a post the account published, a Google Business Profile review (the location is the Profile), or a mention of the account in someone else's post. `containerId` is a plain id rather than a [pointer](https://docs.koil.co/concepts/content#pointers): it groups and lists items, and a container need not be something you can read.

## Targets

`target` is the one thing on the platform the item directly responds to:

-   **A top-level comment:** its post, the same as its container.
-   **A reply:** the comment the platform files it under. Instagram, YouTube, and LinkedIn file a reply to a reply under the top-level comment.
-   **A message:** the message, story, or comment it replies to or quotes, which can be in another container. An Instagram story reply targets an `instagram.stories.posts` item.
-   **A reaction:** what it reacts to.
-   **A delivery status:** the message it reports on, by the `externalId` its publish request returned.

An item responds to at most one thing. `target` is absent when the platform reports nothing it responds to: a message that simply continues the conversation, or a LinkedIn comment event, since LinkedIn's notifications carry no parent. A collection whose platform always reports it requires it, as its schema on the [platform page](https://docs.koil.co/platforms) shows.

List routes that filter by what items respond to take `targetId`: a comment's replies, or the reactions to a LinkedIn post. To respond to an item yourself, pass its `kind` and `externalId` as a publish request's `target`; see [Reply to content](https://docs.koil.co/guides/reply-to-content).

## References

`references` lists the other content or accounts an item's text or body points at, in text order. Each one has:

-   **`type`:** `mention` when the text names an account, or `embed` when the item carries other content inside it, such as a quote post or a shared post. Quoting a message to reply to it is the item's `target`, not an embed. Types are added as platforms report them.
-   **`target`:** a [pointer](https://docs.koil.co/concepts/content#pointers) to what is referenced. A share that arrives with only a URL is `{ permalink }`.
-   **`span`:** where in `text` the reference sits, as `start` and `length` in UTF-16 code units, the units JavaScript strings index, so `text.slice(start, start + length)` is the reference's text. It is absent when the reference is not in the text, such as an embed shown as a card, or when the platform gives no position.

A collection that reports references has `references` in its schema. A `mention` reference is not a mention record: a `*.mentions` collection delivers content that names the connected account, while a `mention` reference marks where an item's text names someone.

## Pointers

A pointer names one thing on the platform outside the item: content, an account, or anything else the platform gives an id or a URL. `target` and each reference's `target` are pointers, with up to three fields:

-   **`externalId`:** the platform's id for it. Match and join on this.
-   **`kind`:** the collection the platform's data places it in, as that item's own `kind` would be. It is absent for an account, or when the platform does not say.
-   **`permalink`:** its URL on the platform, for display and linking only, never as a key: it may point at something private or expired, such as a story after 24 hours. Koil includes it only when the platform sends it or the collection builds it from a documented pattern, so many targets have none; an Instagram id, for one, cannot be turned into a URL.

On a read, a pointer has at least an `externalId` or a `permalink`. On a write, such as a publish `target`, `kind` and `externalId` are both required and `kind` must be a collection that publish accepts, so pass a delivered item's `kind` and `externalId` straight through. An item's own `kind`, `externalId`, and `permalink` are the pointer to it.

## Variants

`variant` names a subtype inside a collection that no other field implies: an Instagram post is a `feed` post or a `reel`, and a mention record says whether the mentioning item is a post or a comment. Where a collection has variants, you choose one when you publish, beside `collection`, and it decides what `args` takes. Whether a comment is a reply is never a variant: that is its `target`.

## Platform payloads

Add `includePlatformRaw=true` to a read or an edit to receive the platform's own payload as `platformRaw` beside Koil's fields, for debugging. It is opaque and platform-defined, Koil never stores it, and events never carry it, so build on Koil's fields.

## Creating and changing content

Content is created by a publish request and changed in place:

-   **Create** a post, comment, reply, or message with `POST /v1/publish-requests`. It answers `202` with a publish request id (or, sent with [`Prefer: wait`](https://docs.koil.co/guides/publishing#waiting-for-the-outcome), `200` with its outcome if it has one within a few seconds), runs now or at its `scheduledAt`, requires an [`Idempotency-Key`](https://docs.koil.co/concepts/idempotency), and reports its outcome on the request and as `publish_request.*` events. See [Publish content](https://docs.koil.co/guides/publishing).
-   **Edit, delete, or act on** an existing item on its own path: `PATCH` or `DELETE` `/v1/profiles/{profileId}/content/{collection}/{externalId}`, or `POST /v1/profiles/{profileId}/content/{collection}/{externalId}/actions` to moderate it, like it, or show a read receipt or typing. Each runs during the request and answers with its result.

The split follows the work. A create may wait for its media to process or for its schedule, and the platform call that creates content cannot safely be repeated, so Koil records each one and runs it as durable, tracked work. An edit, a delete, or an action acts on an item that already has an id and finishes within the request, so there is nothing to track. Which collections support each is on its [platform page](https://docs.koil.co/platforms) and in `GET /v1/collections`.
