# Switch a sync on or off

> Start or pause a sync. The sync answers in state `processing` while it starts or stops; read its status to follow. A sync switched off can be switched on again only after a short wait, which the error names in seconds.

Source: https://docs.stacksync.com/api-reference/syncs/switch_sync

`POST https://api.stacksync.com/v1/workspaces/{workspace_id}/bases/{base_id}/switch`

- Operation: `switch_sync`
- Resource: Syncs
- Access: writes data

## Authentication

- `Authorization: Bearer <key>`: A workspace API key (workspace_…, created by a workspace owner under Workspace settings > Stacksync API) acts with editor rights on that workspace only; a user API key (user_…, created under Profile > Stacksync API) acts as that user in every workspace they belong to. POST, PUT and PATCH requests must send Content-Type: application/json. Every authentication failure answers 403.
- `Content-Type: application/json` on every request with a body.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace_id` | integer | Yes | The workspace the resources belong to |
| `base_id` | string (uuid) | Yes | The sync (a sync is called a base in these paths) |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string (besg \| usnv) | Yes | Data region of the sync (its presence is checked; the value is used as given) |

## Request body

`application/json`. The switch to apply

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `switch_mode` | string (ON \| OFF) | Yes | `ON` to start syncing, `OFF` to pause |

## Returns

### 200 The sync after the switch

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object (SwitchedSync) | Yes | The sync after the switch |
| `data.base_id` | string (uuid) | Yes | The sync |
| `data.switch_mode` | string (ON \| OFF) | Yes | The switch applied |
| `data.base_status` | string | Yes | The state of the sync right after the switch (`processing` while it starts or stops) |

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/bases/{base_id}/switch?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "switch_mode": "ON"
}'
```

## Example response (200)

```json
{
  "data": {
    "base_id": "3f6c1d2e-8a4b-4c7d-9e21-5b6f7a8c9d01",
    "switch_mode": "ON",
    "base_status": "processing"
  }
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | The `region` is missing; the body is not valid JSON; `switch_mode` is missing or not `ON` or `OFF` (`Invalid Request Body`); the sync was switched off too recently to switch on (`Minimum switch on time has not passed`, the message names the seconds left); the switch failed (`Error setting base status to processing`, or the platform's error) | `{ "error": string }` |
| 403 | Forbidden: invalid API key, API key of another workspace, insufficient scope, workspace unavailable, or a non-GET request without `Content-Type: application/json` | `{ "error": string }` |
| 404 | No sync with this id exists in the workspace (`Base not found`) | `{ "error": string }` |

## Related

- [API Reference overview](https://docs.stacksync.com/api-reference): base URLs, regions, pagination, idempotency and errors
- [Authentication](https://docs.stacksync.com/api-reference/authentication): API keys and the 403 answers
- OpenAPI document: https://docs.stacksync.com/openapi.json
- [List syncs](https://docs.stacksync.com/api-reference/syncs/list_syncs)
- [Get a sync](https://docs.stacksync.com/api-reference/syncs/get_sync)
- [Get the status of a sync](https://docs.stacksync.com/api-reference/syncs/get_sync_status)
- [Get sync metrics](https://docs.stacksync.com/api-reference/syncs/get_sync_metrics)
- [Get sync diagnostics](https://docs.stacksync.com/api-reference/syncs/get_sync_diagnostics)
- [Create a sync](https://docs.stacksync.com/api-reference/syncs/create_sync)
- [Update sync settings](https://docs.stacksync.com/api-reference/syncs/update_sync_settings)
- [Edit a sync](https://docs.stacksync.com/api-reference/syncs/edit_sync)
- [Delete a sync](https://docs.stacksync.com/api-reference/syncs/delete_sync)
- [Rename a sync](https://docs.stacksync.com/api-reference/syncs/rename_sync)
- [Set the change capture method](https://docs.stacksync.com/api-reference/syncs/set_sync_app_cdc_method)
- [Set the rate limit of an app](https://docs.stacksync.com/api-reference/syncs/set_sync_app_rate_limit)
- [Set Salesforce Bulk API access](https://docs.stacksync.com/api-reference/syncs/set_sync_app_bulk_api_access)
- [Set delete protection of an app](https://docs.stacksync.com/api-reference/syncs/set_sync_app_delete_protection)