# Auto-Sync

> Auto-sync connection status, sync history, and manual sync trigger for broker integrations.
> Source: https://help.tradavity.com/api-docs/autosync
> Category: Resources

---

Inspect broker auto-sync connections, read sync history, and trigger a manual sync.

## GET /autosync/connections

**Scope:** `read:autosync`

List your auto-sync connections. No token material is ever exposed.

## GET /autosync/connections/{id}

**Scope:** `read:autosync`

Single connection.

## GET /autosync/log

**Scope:** `read:autosync`

Sync history.

---

## POST /autosync/connections/{id}/sync

**Scope:** `write:autosync` · **Plan gate:** Pro

Trigger an immediate sync on a broker connection. Routes through the same dupe-detection + import pipeline the settings UI uses, so a manual sync from the API is byte-identical to one triggered from the dashboard.

No request body. The connection’s configured Tradavity account_id is the import target.

| Status | Code | Meaning |
| --- | --- | --- |
| 200 | (no error code) | Sync ran. Body `data` contains `connection_id`, `log_id`, `imported`, `skipped`, `total_fetched`, `total_trades`, `total_pnl`, `errors[]`, and a human-readable `message`. |
| 400 | `validation_error` | Connection inactive or no broker account selected. |
| 401 | `token_expired` | Broker token expired or could not be refreshed. The user needs to reconnect via the settings UI. |
| 404 | `not_found` | No connection with that id, or it doesn’t belong to you. |
| 429 | `limit_reached` | Pro plan required for sync. |
| 429 | `connection_sync_cooldown` | Per-connection cooldown — manual syncs are capped to once every 20 seconds per connection to protect the upstream broker API from amplification. Distinct from the key-level rate limit. Headers: `X-RateLimit-Scope: connection-sync`, `Retry-After: <seconds>`. `error.details.retry_after_seconds` mirrors the header. Cron-triggered syncs (the 15-minute auto-sync schedule) bypass this gate. |
| 502 | `broker_api_error` | Upstream broker API returned an error. Retry later. |
| 500 | `sync_failed` | Sync pipeline raised an unexpected error (parser crash, DB transaction abort, etc.). Retrying is safe — the operation is idempotent on the broker side. |

```bash
# Replace 12 with one of your connection_ids from GET /autosync/connections
curl -X POST "https://app.tradavity.com/api/v1/autosync/connections/12/sync" \
  -H "Authorization: Bearer tvty_YOUR_KEY_HERE" \
  -H "Idempotency-Key: $(uuidgen)"
```

The Idempotency-Key cache returns the same imported/skipped numbers on replay without hitting the broker again. Useful when a flaky network kills the response but the sync already ran.
