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

# CLI automation

> Use JSON, stdin, exit codes, compact output, and masked CI secrets.

The PostlyBee CLI is intentionally JSON-first. Human-readable output is formatted with indentation; `--raw-json` emits one compact line for `jq`, log processors, and AI-agent tool adapters.

## JSON input

Commands that accept complex payloads require exactly one input source:

```bash theme={null}
postlybee posts:create --file post.json
postlybee posts:create --data '{"type":"draft",...}'
postlybee posts:create --stdin < post.json
```

Pipelines can generate payloads without temporary files:

```bash theme={null}
jq -n \
  --arg account "$ACCOUNT_ID" \
  --arg content "$POST_CONTENT" \
  '{
    type: "draft",
    shortLink: false,
    tags: [],
    posts: [{
      integration: {id: $account},
      value: [{content: $content, image: []}],
      settings: {}
    }]
  }' | postlybee --raw-json posts:create --stdin
```

## CI configuration

Store credentials in masked CI secrets instead of committing the credentials file:

```yaml theme={null}
env:
  POSTLYBEE_API_TOKEN: ${{ secrets.POSTLYBEE_API_TOKEN }}
  POSTLYBEE_WORKSPACE_ID: ${{ vars.POSTLYBEE_WORKSPACE_ID }}
```

Then run a deterministic command:

```bash theme={null}
postlybee --raw-json ping
postlybee --raw-json posts:create --file campaign.json
```

## Exit codes and errors

Successful commands exit with `0`. Authentication, validation, permission, provider, and network errors exit with `1` and print JSON:

```json theme={null}
{
  "error": "Insufficient API token scope",
  "status": 403,
  "details": {
    "requiredScopes": ["posts:write"]
  },
  "retryAfter": null
}
```

For `429 Too Many Requests`, use `retryAfter` to delay the next attempt. Avoid immediate retry loops that consume the Workspace allowance.

## Self-hosted automation

```bash theme={null}
export POSTLYBEE_API_URL="https://api.example.com"
postlybee workspaces:list
```

The CLI talks only to the Public API. It never connects directly to PostgreSQL, Redis, Temporal, or internal NestJS services, so the same package works with PostlyBee Cloud and compatible self-hosted deployments.

## AI agents

Agents can call the CLI as a subprocess and parse `--raw-json`. Use read-only Token scopes during discovery, require human confirmation before publishing, and issue a separate write Token only to the execution environment that needs it. For clients with native MCP support, prefer the [MCP integration](/mcp/overview) instead of wrapping shell commands.
