> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://api.docs.siftsy.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://api.docs.siftsy.com/_mcp/server.

# Add posts to collections, remove them, or replace their collections

POST https://api.siftsy.app/analyst/v1/content/posts/collections
Content-Type: application/json

Requires `posts:write`. Changes which collections up to 100 posts
already on the team are in, by `postIds` and/or `links`. Responds
`200` immediately. Does not create posts and does not spend credits.

`operation`:

* `add` puts each post in the listed collections and keeps the ones it is already in
* `remove` takes each post out of the listed collections
* `set` replaces every collection the post is in with the listed ones (`collections: []` takes it out of all of them)

`collections` takes the same refs as the add routes: `{ "id": "…" }`
or `{ "name": "…" }` (case-insensitive). On `add` and `set` a name
that matches no active collection creates a campaign (`created: true`),
but only when at least one named post is on the team. `remove` never
creates; an unknown name is `404` with `error.code:
collection_not_found`. A name that matches more than one collection
is `409 collection_name_ambiguous`, and an id on another team is `404`.
Nothing is written in either case.

Post misses are per-post rows, as on `POST /content/posts/tags`:
`not_on_team` (link), `not_found` (id), `duplicate_in_batch`,
`unsupported_platform`, `invalid_url`. `teamId` targets an Enterprise
sub-team as on the other content routes.

Rate class `content_post_collections` (20 / minute, 500 / day per key).

Reference: https://api.docs.siftsy.com/api-reference/siftsy-analyst-api/update-post-collections

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.
- `X-Api-Key` header (required) — API Key authentication via header

## Servers

- `https://api.siftsy.app/analyst/v1` (Production, default)
- `http://localhost:3000/analyst/v1` (Local development)

## Request

### Body (application/json)

This endpoint expects an UpdatePostCollectionsRequest.

- `operation` (enum, required) — `add` merges. `remove` drops the listed collections and never creates one. `set` replaces every collection the post is in (`collections: []` takes it out of all of them).
  - Allowed values: `add`, `remove`, `set`
- `collections` (list of CollectionRef, required) — Must be non-empty for `add` and `remove`.
- `postIds` (list of string, optional) — Post ids on the target team (from `GET /posts`)
- `links` (list of string, optional) — Post URLs already on the target team. A link that is not on the team is rejected.
- `teamId` (string, optional) — Enterprise keys only — a sub-team of the key's enterprise

## Response

### 200

Membership update applied. Per-post rows give each post's collections afterwards and what was rejected.

- `data` (EnvelopePostCollectionsData, optional)
- `meta` (EnvelopePostCollectionsMeta, optional)

## Errors

### 400 Bad Request Error

Invalid request

- `any`

### 403 Forbidden Error

Missing required scope

- `any`

### 404 Not Found Error

Resource not found

- `any`

### 409 Conflict Error

A collection name matches more than one active collection. `error.code` is `collection_name_ambiguous` and `error.candidates[]` lists the ids. Nothing was written.

- `any`

### 429 Too Many Requests Error

A per-minute cap, a per-day budget, or the daily transfer cap was exceeded. `error.message` is `Rate limit exceeded`, `Daily request limit exceeded`, or `Daily transfer limit exceeded`. Honor `Retry-After` (next UTC minute for burst caps; UTC midnight for daily budgets). Sized for a scheduled BI refresh: burst caps that a sequential loop cannot trip, daily budgets that fit eight full refreshes a day of a 500-post workspace or one full refresh plus hourly incrementals. Defaults: 300/minute and 10,000/day globally, with class budgets for per-post comment samples (120/min, 1,000/day), analysis-wide comment samples (20/min, 300/day), collection posts (60/min, 1,000/day), analysis reads (60/min, 2,000/day), analysis create (10/min, 100/day), AI search and written answers (2/min, 10/day), scans, breakdowns, and link matching (20/min, 500/day each), analysis exports (30/min, 500/day), adding posts (10/min, 200/day), adding accounts (2/min, 20/day), refreshing posts (10/min, 200/day), tagging and archiving posts (20/min, 500/day each), share links (10/min, 200/day), and content job polls (60/min, 2,000/day). Daily transfer cap 500 MB. `POST /analyses` with AI also returns `429` with `error.code: ai_budget_exceeded` when the team's daily AI budget is spent; `error.budget` has `used`, `limit`, and `resetsAt`, and `Retry-After` runs to UTC midnight.

- `any`

## Types

### CollectionRef

Exactly one of `id` or `name`. `id` must be an active collection on the target team. `name` reuses an exact (case-insensitive) match on an active collection, otherwise creates one. Ambiguous names return `409 collection_name_ambiguous`. A bare `name` matches a collection of any type anywhere on the team. Once you pass `type` or `parentId`, the name only matches a collection of that type in that place (a `group` under that `parentId`). If the name is already used somewhere else on the team, the request fails with `409 collection_name_taken` and `error.candidates` instead of reusing that collection or creating a second one with the same name.

- `id` (string, optional) — Existing collection id
- `name` (string, optional) — Collection name to match or create
- `type` (enum, optional, default: campaign) — Structural type when creating by name
  - Allowed values: `campaign`, `group`
- `parentId` (string, optional) — With `type: group`, the campaign to nest the new group under. Groups nest one level, so this must be a campaign (`400` otherwise).

### EnvelopePostCollectionsData

- `operation` (enum, optional)
  - Allowed values: `add`, `remove`, `set`
- `teamId` (string, optional)
- `collections` (list of EnvelopePostCollectionsDataCollectionsItems, optional) — The collections the request named, resolved. Empty when no named post was on the team.
- `counts` (EnvelopePostCollectionsDataCounts, optional)
- `updated` (list of PostCollectionsResult, optional)
- `rejected` (list of PostCollectionsResult, optional)
- `failed` (list of PostCollectionsResult, optional)

### EnvelopePostCollectionsMeta

### EnvelopePostCollectionsDataCollectionsItems

- `id` (string, optional)
- `name` (string, optional, nullable)
- `type` (enum, optional)
  - Allowed values: `campaign`, `group`
- `created` (boolean, optional) — True when this request created the collection

### EnvelopePostCollectionsDataCounts

- `requested` (integer, optional)
- `updated` (integer, optional)
- `rejected` (integer, optional)
- `failed` (integer, optional)

### PostCollectionsResult

- `postId` (string, optional, nullable)
- `link` (string, optional, nullable)
- `collectionIds` (list of string, optional) — Every collection the post is in after the update
- `reason` (string, optional, nullable) — `not_on_team`, `not_found`, `duplicate_in_batch`, `unsupported_platform`, `invalid_url`, or `update_failed`

## Examples

### content_updatePostCollections_example

**Response**

```json
{
  "data": {
    "operation": "add",
    "teamId": "team_2f8c1a",
    "collections": [
      {
        "id": "col_9a1",
        "name": "Q4 Launch",
        "type": "campaign",
        "created": false
      }
    ],
    "counts": {
      "requested": 3,
      "updated": 2,
      "rejected": 1,
      "failed": 0
    },
    "updated": [
      {
        "postId": "post_01j9y",
        "link": "https://www.tiktok.com/@dove/video/7412345678901234567",
        "collectionIds": [
          "col_9a1"
        ]
      },
      {
        "postId": "post_01j9z",
        "link": "https://www.instagram.com/reel/C9AbCdEfGhI/",
        "collectionIds": [
          "col_2b7",
          "col_9a1"
        ]
      }
    ],
    "rejected": [
      {
        "postId": null,
        "link": "https://www.tiktok.com/@missing/video/1",
        "reason": "not_on_team"
      }
    ],
    "failed": []
  },
  "meta": {}
}
```

**SDK Code**

```python content_updatePostCollections_example
import requests

url = "https://api.siftsy.app/analyst/v1/content/posts/collections"

headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript content_updatePostCollections_example
const url = 'https://api.siftsy.app/analyst/v1/content/posts/collections';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go content_updatePostCollections_example
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.siftsy.app/analyst/v1/content/posts/collections"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby content_updatePostCollections_example
require 'uri'
require 'net/http'

url = URI("https://api.siftsy.app/analyst/v1/content/posts/collections")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java content_updatePostCollections_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.siftsy.app/analyst/v1/content/posts/collections")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php content_updatePostCollections_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.siftsy.app/analyst/v1/content/posts/collections', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp content_updatePostCollections_example
using RestSharp;

var client = new RestClient("https://api.siftsy.app/analyst/v1/content/posts/collections");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift content_updatePostCollections_example
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.siftsy.app/analyst/v1/content/posts/collections")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Add posts already on the team to a collection

**Request**

```json
{
  "operation": "add",
  "collections": [
    {
      "name": "Q4 Launch"
    }
  ],
  "postIds": [
    "post_01j9z"
  ],
  "links": [
    "https://www.tiktok.com/@dove/video/7412345678901234567"
  ]
}
```

**Response**

```json
{
  "data": {
    "operation": "add",
    "teamId": "team_2f8c1a",
    "collections": [
      {
        "id": "col_9a1",
        "name": "Q4 Launch",
        "type": "campaign",
        "created": false
      }
    ],
    "counts": {
      "requested": 3,
      "updated": 2,
      "rejected": 1,
      "failed": 0
    },
    "updated": [
      {
        "postId": "post_01j9y",
        "link": "https://www.tiktok.com/@dove/video/7412345678901234567",
        "collectionIds": [
          "col_9a1"
        ]
      },
      {
        "postId": "post_01j9z",
        "link": "https://www.instagram.com/reel/C9AbCdEfGhI/",
        "collectionIds": [
          "col_2b7",
          "col_9a1"
        ]
      }
    ],
    "rejected": [
      {
        "postId": null,
        "link": "https://www.tiktok.com/@missing/video/1",
        "reason": "not_on_team"
      }
    ],
    "failed": []
  },
  "meta": {}
}
```

**SDK Code**

```python Add posts already on the team to a collection
import requests

url = "https://api.siftsy.app/analyst/v1/content/posts/collections"

payload = {
    "operation": "add",
    "collections": [{ "name": "Q4 Launch" }],
    "postIds": ["post_01j9z"],
    "links": ["https://www.tiktok.com/@dove/video/7412345678901234567"]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Add posts already on the team to a collection
const url = 'https://api.siftsy.app/analyst/v1/content/posts/collections';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"operation":"add","collections":[{"name":"Q4 Launch"}],"postIds":["post_01j9z"],"links":["https://www.tiktok.com/@dove/video/7412345678901234567"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Add posts already on the team to a collection
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.siftsy.app/analyst/v1/content/posts/collections"

	payload := strings.NewReader("{\n  \"operation\": \"add\",\n  \"collections\": [\n    {\n      \"name\": \"Q4 Launch\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9z\"\n  ],\n  \"links\": [\n    \"https://www.tiktok.com/@dove/video/7412345678901234567\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Add posts already on the team to a collection
require 'uri'
require 'net/http'

url = URI("https://api.siftsy.app/analyst/v1/content/posts/collections")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"operation\": \"add\",\n  \"collections\": [\n    {\n      \"name\": \"Q4 Launch\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9z\"\n  ],\n  \"links\": [\n    \"https://www.tiktok.com/@dove/video/7412345678901234567\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Add posts already on the team to a collection
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.siftsy.app/analyst/v1/content/posts/collections")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"operation\": \"add\",\n  \"collections\": [\n    {\n      \"name\": \"Q4 Launch\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9z\"\n  ],\n  \"links\": [\n    \"https://www.tiktok.com/@dove/video/7412345678901234567\"\n  ]\n}")
  .asString();
```

```php Add posts already on the team to a collection
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.siftsy.app/analyst/v1/content/posts/collections', [
  'body' => '{
  "operation": "add",
  "collections": [
    {
      "name": "Q4 Launch"
    }
  ],
  "postIds": [
    "post_01j9z"
  ],
  "links": [
    "https://www.tiktok.com/@dove/video/7412345678901234567"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Add posts already on the team to a collection
using RestSharp;

var client = new RestClient("https://api.siftsy.app/analyst/v1/content/posts/collections");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"operation\": \"add\",\n  \"collections\": [\n    {\n      \"name\": \"Q4 Launch\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9z\"\n  ],\n  \"links\": [\n    \"https://www.tiktok.com/@dove/video/7412345678901234567\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Add posts already on the team to a collection
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "operation": "add",
  "collections": [["name": "Q4 Launch"]],
  "postIds": ["post_01j9z"],
  "links": ["https://www.tiktok.com/@dove/video/7412345678901234567"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.siftsy.app/analyst/v1/content/posts/collections")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Take a post out of a collection

**Request**

```json
{
  "operation": "remove",
  "collections": [
    {
      "id": "col_9a1"
    }
  ],
  "postIds": [
    "post_01j9y"
  ]
}
```

**Response**

```json
{
  "data": {
    "operation": "add",
    "teamId": "team_2f8c1a",
    "collections": [
      {
        "id": "col_9a1",
        "name": "Q4 Launch",
        "type": "campaign",
        "created": false
      }
    ],
    "counts": {
      "requested": 3,
      "updated": 2,
      "rejected": 1,
      "failed": 0
    },
    "updated": [
      {
        "postId": "post_01j9y",
        "link": "https://www.tiktok.com/@dove/video/7412345678901234567",
        "collectionIds": [
          "col_9a1"
        ]
      },
      {
        "postId": "post_01j9z",
        "link": "https://www.instagram.com/reel/C9AbCdEfGhI/",
        "collectionIds": [
          "col_2b7",
          "col_9a1"
        ]
      }
    ],
    "rejected": [
      {
        "postId": null,
        "link": "https://www.tiktok.com/@missing/video/1",
        "reason": "not_on_team"
      }
    ],
    "failed": []
  },
  "meta": {}
}
```

**SDK Code**

```python Take a post out of a collection
import requests

url = "https://api.siftsy.app/analyst/v1/content/posts/collections"

payload = {
    "operation": "remove",
    "collections": [{ "id": "col_9a1" }],
    "postIds": ["post_01j9y"]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Take a post out of a collection
const url = 'https://api.siftsy.app/analyst/v1/content/posts/collections';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"operation":"remove","collections":[{"id":"col_9a1"}],"postIds":["post_01j9y"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Take a post out of a collection
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.siftsy.app/analyst/v1/content/posts/collections"

	payload := strings.NewReader("{\n  \"operation\": \"remove\",\n  \"collections\": [\n    {\n      \"id\": \"col_9a1\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9y\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Take a post out of a collection
require 'uri'
require 'net/http'

url = URI("https://api.siftsy.app/analyst/v1/content/posts/collections")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"operation\": \"remove\",\n  \"collections\": [\n    {\n      \"id\": \"col_9a1\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9y\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Take a post out of a collection
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.siftsy.app/analyst/v1/content/posts/collections")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"operation\": \"remove\",\n  \"collections\": [\n    {\n      \"id\": \"col_9a1\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9y\"\n  ]\n}")
  .asString();
```

```php Take a post out of a collection
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.siftsy.app/analyst/v1/content/posts/collections', [
  'body' => '{
  "operation": "remove",
  "collections": [
    {
      "id": "col_9a1"
    }
  ],
  "postIds": [
    "post_01j9y"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Take a post out of a collection
using RestSharp;

var client = new RestClient("https://api.siftsy.app/analyst/v1/content/posts/collections");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"operation\": \"remove\",\n  \"collections\": [\n    {\n      \"id\": \"col_9a1\"\n    }\n  ],\n  \"postIds\": [\n    \"post_01j9y\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Take a post out of a collection
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "operation": "remove",
  "collections": [["id": "col_9a1"]],
  "postIds": ["post_01j9y"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.siftsy.app/analyst/v1/content/posts/collections")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```