# Run one X action over many items

> x_batch — One X write operation (post_set_like, user_set_follow, dm_send, post_reply…) over up to 1 000 items.

Source: https://x.builera.app/docs/en/reference/x_batch

`x_batch` · Write on X (creates a job)

One X write operation (post_set_like, user_set_follow, dm_send, post_reply…) over up to 1 000 items. Give items [{account, args}] or a selector {account_ids, group_ids} plus args_list (every account × every args). Each item is queued like a direct call (same limits, run hours, do-not-contact). Optional spacing_seconds {min,max} between items of the same account. dry_run=true returns what would be queued and why any item is refused. Follow with x_batch_get; the batch.completed event fires when every item has ended.

| | |
|---|---|
| REST | `POST /api/public/v1/batches` |
| MCP tool | `x_batch` |
| Permission needed | `accounts.run` — Owner, Manager, Operator |
| Scope group | `x:engage` |
| Group | Actions on X |
| Shown up front in profiles | Automation, Infrastructure |

## Input {#input}

| Field | Type | Required | Description |
|---|---|---|---|
| `operation` | string (0–64 chars) | Yes | Operation id of an X write that takes an account (see tools_search). |
| `items` | array of object (0–1000 items) | No |  |
| `selector` | object | No | Which accounts: the union of account_ids and the members of group_ids. Empty = no account (never all). |
| `args_list` | array of object (0–1000 items) | No | With selector: each args object runs on every selected account. |
| `spacing_seconds` | object | No | Extra wait between two items of the same account (default none: the account's own queue order and human pacing only). |
| `dry_run` | boolean | No |  |

## Result {#output}

Creates a job for the X account's VPS. REST waits up to `wait` seconds (default 15, max 20): when done it returns 200 with the result, otherwise 202 with `Location: /api/public/v1/jobs/{job_id}`. The final status is succeeded, failed, cancelled or unknown.

> [!IMPORTANT]
> Needs an idempotency key (`Idempotency-Key`, 8–128 characters). Retrying with the same key never repeats the action.

> [!WARNING]
> A job that ends `unknown` may already have happened on X: never resend it with a new idempotency key.

## Example {#example}

### Call over REST {#example-rest}

```bash
curl -X POST "https://reach-link-craft.lovable.app/api/public/v1/batches" \
  -H "Authorization: Bearer $XBUDDY_API_KEY" \
  -H "Idempotency-Key: 6f1c2a90-example-key" \
  -H "Content-Type: application/json" \
  -d '{"operation":"example"}'
```

### Call over MCP {#example-mcp}

```json
{
  "method": "tools/call",
  "params": {
    "name": "x_batch",
    "arguments": {
      "operation": "example",
      "idempotency_key": "6f1c2a90-example-key"
    }
  }
}
```

## Errors you may get {#errors}

| Code | HTTP | Retryable |
|---|---|---|
| [`unauthorized`](/docs/en/errors/unauthorized) | 401 | No |
| [`key_expired`](/docs/en/errors/key_expired) | 401 | No |
| [`integration_revoked`](/docs/en/errors/integration_revoked) | 401 | No |
| [`connection_not_linked`](/docs/en/errors/connection_not_linked) | 403 | No |
| [`integration_paused`](/docs/en/errors/integration_paused) | 403 | No |
| [`workspace_integrations_paused`](/docs/en/errors/workspace_integrations_paused) | 403 | No |
| [`integration_authorization_lost`](/docs/en/errors/integration_authorization_lost) | 403 | No |
| [`workspace_suspended`](/docs/en/errors/workspace_suspended) | 403 | No |
| [`forbidden`](/docs/en/errors/forbidden) | 403 | No |
| [`invalid_input`](/docs/en/errors/invalid_input) | 422 | No |
| [`rate_limited`](/docs/en/errors/rate_limited) | 429 | Yes |
| [`internal`](/docs/en/errors/internal) | 500 | Yes |
| [`read_only`](/docs/en/errors/read_only) | 403 | No |
| [`idempotency_key_required`](/docs/en/errors/idempotency_key_required) | 428 | No |
| [`idempotency_conflict`](/docs/en/errors/idempotency_conflict) | 409 | No |
| [`idempotency_processing`](/docs/en/errors/idempotency_processing) | 409 | Yes |
| [`conflict`](/docs/en/errors/conflict) | 409 | No |
| [`precondition_failed`](/docs/en/errors/precondition_failed) | 422 | No |
| [`agent_too_old`](/docs/en/errors/agent_too_old) | 422 | No |
| [`unsupported_by_account`](/docs/en/errors/unsupported_by_account) | 422 | No |

[Back to all operations](/docs/en/reference)
