> ## Documentation Index
> Fetch the complete documentation index at: https://docs.postsyncer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Run the API from your terminal

> postsyncer-cli sends API v1 requests from a terminal, a script or CI: posts, media, folders, comments, analytics, workspaces, accounts and labels.

`postsyncer-cli` is PostSyncer's command-line tool. Each command sends one API v1 request with your API key and prints PostSyncer's JSON answer. It takes the same fields as the API, so the [API reference](https://docs.postsyncer.com/api-reference/introduction.md) describes every body you send.

It needs Node.js 20 or later. The command you run is `postsyncer`.

## Install

```bash npm theme={null}
npm install -g postsyncer-cli
```

```bash pnpm theme={null}
pnpm add -g postsyncer-cli
```

```bash npx theme={null}
npx postsyncer-cli --help
```

`npx` runs it once without installing. Every command takes `--help`, such as `postsyncer posts --help`.

## Sign in with a key

1. Make a key in [Settings → API](https://app.postsyncer.com/settings/api). Give it only the permissions your commands need: the [table below](#commands) lists them. [Authentication](https://docs.postsyncer.com/essentials/authentication.md) explains keys and permissions.
2. Put the key in `POSTSYNCER_TOKEN` and check it:

```bash theme={null}
export POSTSYNCER_TOKEN="YOUR_API_KEY"
postsyncer ping
```

```text Output theme={null}
PostSyncer: authenticated — GET /workspaces succeeded.
Workspaces (1): #4815 Halden Coffee
```

`ping` reads `GET /workspaces`, so the key needs `workspaces:read`. To use a key for one command only, pass it with `-t` or `--token` instead.

## Find your ids

```bash theme={null}
postsyncer workspaces list
postsyncer accounts list
```

Note the workspace's `id` and the `id` of the account you post to. The examples below use workspace `4815` and account `16234`: put your own ids in their place.

## Save a draft

Commands that send a body take JSON in one of three ways: `--file` (`-f`) with a path, `--data` (`-d`) with the JSON itself, or `--stdin` to read it from a pipe. Use exactly one.

Save this as `draft.json`:

```json draft.json theme={null}
{
  "workspace_id": 4815,
  "schedule_type": "draft",
  "content": [
    { "text": "Oat-milk flat whites are back at Halden Coffee this spring." }
  ],
  "accounts": [{ "id": 16234 }]
}
```

```bash theme={null}
postsyncer posts create --file draft.json
```

The answer is the new post, with its `id`. A draft goes nowhere. On Windows, `--file` is simpler than `--data`, since each shell quotes differently.

## Schedule it

`posts update` sends `PUT /posts/{id}` with the same fields as create. Send the `workspace_id` and the full `content` again. Save this as `schedule.json`:

```json schedule.json theme={null}
{
  "workspace_id": 4815,
  "schedule_type": "schedule",
  "schedule_for": { "date": "2030-03-15", "time": "09:00" },
  "content": [
    { "text": "Oat-milk flat whites are back at Halden Coffee this spring." }
  ]
}
```

```bash theme={null}
postsyncer posts update POST_ID --file schedule.json
```

The time is in the workspace's timezone. The key also needs `posts:schedule`. Without it, the command prints the `403` and nothing is saved. Leave `accounts` out and the post keeps its accounts. [Update post](https://docs.postsyncer.com/api-reference/posts/update.md) has every rule.

## Upload media

```bash theme={null}
postsyncer media upload-file --workspace 4815 --file ./latte-art.jpg
```

`--workspace` and `--file` are required, and `--folder` puts the file in a media folder. The CLI sends the file to the upload host, `https://upload.postsyncer.com/api/v1`, and reads the whole file into memory first. Put the answer's `media.id` in a post's `content[].media`.

To copy files from links into the library instead, send `POST /media/upload/url`:

```bash theme={null}
postsyncer media upload-url --data '{"workspace_id":4815,"urls":["https://cdn.postsyncer.com/examples/latte-art.jpg"]}'
```

[Add media](https://docs.postsyncer.com/guides/media.md) says which files each network takes.

## Options for every command

Put these before the command, such as `postsyncer --raw-json posts list`.

| Option | What it does |
| - | - |
| `-t`, `--token` | The API key, when `POSTSYNCER_TOKEN` isn't set. |
| `--raw-json` | Prints each answer as one line of JSON, for logs and `jq`. |
| `--base-url` | Another API address. Use it only if PostSyncer support asks you to. |
| `--upload-base-url` | Another upload host. Use it only if PostSyncer support asks you to. |

```bash theme={null}
postsyncer --raw-json posts list | jq '.data[] | {id, status}'
```

## Commands

Each command sends one request. The key needs the permission in the last column.

| Command | Request | Permission |
| - | - | - |
| `ping`, `workspaces list` | `GET /workspaces` | `workspaces:read` |
| `accounts list` | `GET /accounts` | `accounts:read` |
| `accounts delete <id>` | `DELETE /accounts/{id}` | `accounts:delete` |
| `posts list` | `GET /posts` | `posts:read` |
| `posts get <id>` | `GET /posts/{id}` | `posts:read` |
| `posts get-by-url <url>` | `GET /posts/by-url/{post_url}` | `posts:read` |
| `posts get-by-platform-id <id>` | `GET /posts/by-platform-post-id/{platform_post_id}` | `posts:read` |
| `posts create` | `POST /posts` | `posts:create`, plus `posts:schedule` or `posts:publish` to send it |
| `posts update <id>` | `PUT /posts/{id}` | `posts:update`, plus `posts:schedule` or `posts:publish` to send it |
| `posts delete <id>` | `DELETE /posts/{id}` | `posts:delete` |
| `posts analyze-twitter --url <url> --question <text>` | `POST /posts/analyze-twitter` | `posts:read` |
| `posts auto-plug <postId>` | `PATCH /posts/{post}/auto-plug` | `posts:update` |
| `posts comment-moderation <postId>` | `PATCH /posts/{post}/comment-moderation` | `posts:update` |
| `posts contact-collection <postId>` | `PATCH /posts/{post}/contact-collection` | `posts:update` |
| `media list` | `GET /media` | `media:read` |
| `media get <id>` | `GET /media/{media_id}` | `media:read` |
| `media delete <id>` | `DELETE /media/{media_id}` | `media:delete` |
| `media upload-file` | `POST /media/upload/file` on the upload host | `media:create` |
| `media upload-url` | `POST /media/upload/url` | `media:create` |
| `folders list` | `GET /folders` | `folders:read` |
| `folders get <id>` | `GET /folders/{id}` | `folders:read` |
| `folders create` | `POST /folders` | `folders:create` |
| `folders update <id>` | `PUT /folders/{id}` | `folders:update` |
| `folders delete <id>` | `DELETE /folders/{id}` | `folders:delete` |
| `comments list --post <postId>` | `GET /comments?post_id=` | `comments:read` |
| `comments get <id>` | `GET /comments/{id}` | `comments:read` |
| `comments create` | `POST /comments` | `comments:create` |
| `comments update <id>` | `PUT /comments/{id}` | `comments:update` |
| `comments delete <id>` | `DELETE /comments/{id}` | `comments:delete` |
| `comments hide <id>` | `PATCH /comments/{id}/hide` | `comments:update` |
| `comments sync` | `POST /comments/sync` | `comments:read` |
| `labels list` | `GET /labels` | `labels:read` |
| `labels get <id>` | `GET /labels/{id}` | `labels:read` |
| `labels create` | `POST /labels` | `labels:create` |
| `labels update <id>` | `PUT /labels/{id}` | `labels:update` |
| `labels delete <id>` | `DELETE /labels/{id}` | `labels:delete` |
| `analytics all` | `GET /analytics` | `analytics:read` |
| `analytics workspace <id>` | `GET /analytics/workspaces/{id}` | `analytics:read` |
| `analytics post <id>` | `GET /analytics/posts/{id}` | `analytics:read` |
| `analytics account <id>` | `GET /analytics/accounts/{id}` | `analytics:read` |
| `analytics sync-post <id>` | `POST /analytics/posts/{id}/sync` | `analytics:read` |

What to know about some of them:

* `posts get-by-url` encodes the link for you. Pass it as you copied it.
* On the Free plan, `posts analyze-twitter` is refused, and so is turning on comment moderation or contact collection. Creating and changing labels is on paid plans too. [Plan limits](https://docs.postsyncer.com/plan-limits.md) has the list.
* `folders delete` deletes only an empty folder. A folder with subfolders or files answers `422`: move or delete what's in it first.
* `comments hide` asks the network to hide the comment. On a network that can't hide, it answers `422` and sends nothing. See [Answer comments](https://docs.postsyncer.com/guides/comments.md#hide-or-delete-a-comment).
* `comments sync` takes `{"post_id": POST_ID}` as its body.
* `labels update` needs both `name` and `color`.
* `accounts delete` disconnects the account. Scheduled posts that go only to it move to drafts. See [Delete an account](https://docs.postsyncer.com/api-reference/accounts/delete.md).
* `posts delete` can't be undone. [Test safely](https://docs.postsyncer.com/test-safely.md#what-cant-be-undone) says what it removes on each network.

The CLI doesn't cover the brand, snippets, campaigns, webhooks, Google reviews, approvals, post history or connect links. Use the [API](https://docs.postsyncer.com/api-reference/introduction.md) or the [MCP server](https://docs.postsyncer.com/mcp/overview.md) for those.

## When a command fails

The CLI prints the status and PostSyncer's answer, then exits with code `1`:

```text Output theme={null}
HTTP 403 Forbidden — {"message":"This API key does not have the \"posts:schedule\" permission. Edit the key in PostSyncer under Settings → API to grant it."}
If this is a permission error, edit the token at https://app.postsyncer.com/settings/api
```

After a `401` it says to check the key, after a `403` to check its permissions. [Error handling](https://docs.postsyncer.com/essentials/error-handling.md) lists every answer.

## In scripts and CI

* Keep the key in your CI's secret store and pass it as `POSTSYNCER_TOKEN`. Don't commit it or paste it into chats.
* A non-zero exit code means the request failed, so a CI step stops there.
* The CLI shares the [rate limit](https://docs.postsyncer.com/rate-limits.md) with the API and MCP: 60 requests a minute per person. Wait and retry when a run gets `429`.
* Each command runs once. After a timeout, check with `posts list` before you create the post again, or you may make two.

## Related

> [card] [Quickstart](https://docs.postsyncer.com/quickstart.md)
>
> The same steps with curl, Node.js or Python.

> [card] [MCP server](https://docs.postsyncer.com/mcp/overview.md)
>
> Let an AI agent do the same work.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.