## Toggle flow activity

`POST /v1/tasks/flows/:flowId/activate`

Turns an inactive flow on and an active flow off: each call switches the flow to the opposite state.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `flowId` (path) | number | yes | Flow ID. List: [`GET /v1/tasks/flows`](/docs/entities/tasks/flows-list) |

No request body is required; fields in the body are ignored.

## Examples

### curl — personal key

```bash
curl -X POST 'https://vibecode.bitrix24.com/v1/tasks/flows/20/activate' \
  -H 'X-Api-Key: YOUR_API_KEY'
```

### curl — OAuth application

```bash
curl -X POST 'https://vibecode.bitrix24.com/v1/tasks/flows/20/activate' \
  -H 'X-Api-Key: YOUR_APP_KEY' \
  -H 'Authorization: Bearer USER_SESSION_TOKEN'
```

### JavaScript — personal key

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/tasks/flows/20/activate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})
const result = await response.json()
console.log(result.data)
```

### JavaScript — OAuth application

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/tasks/flows/20/activate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})
const result = await response.json()
console.log(result.data)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success |
| `data` | boolean | `true` — the flow was toggled. The response is the same whether the flow was turned on or off. Read the new state from the `active` field in [`GET /v1/tasks/flows/:flowId`](/docs/entities/tasks/flows-get) |

## Response example

```json
{
  "success": true,
  "data": true
}
```

## Error response example

422 — no flow with this ID exists:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Flow with this ID does not exist.",
    "b24Code": "0"
  }
}
```

The `error.message` text comes in the Bitrix24 account language.

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `flowId` is not a positive integer: `flowId must be a positive safe integer` |
| 400 | `FST_ERR_CTP_EMPTY_JSON_BODY` | The `Content-Type: application/json` header is sent with an empty body. Remove the header |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `INVALID_API_KEY` | The key is not found |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens |
| 403 | `SCOPE_DENIED` | The key has neither the `task` nor the `tasks` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode. `error.details.switchUrl` holds the address of the section where the mode is changed |
| 422 | `BITRIX_ERROR` | No flow with this `flowId` exists: `Flow with this ID does not exist.` |
| 429 | `RATE_LIMITED` | The request rate to Bitrix24 or to the platform is exceeded. Retry after the delay in the `Retry-After` header |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unreachable or returned a server error |
| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**The toggle is not retried automatically.** The `503 BITRIX_TIMEOUT` and `502 BITRIX_UNAVAILABLE` responses do not tell whether the flow was toggled, and the platform does not retry such a call on its own: a retry would return the flow to its previous state. Before calling the method again, read the `active` field in [`GET /v1/tasks/flows/:flowId`](/docs/entities/tasks/flows-get).

## See also

- [Flows and flow tasks](/docs/entities/tasks/flows)
- [Get a flow](/docs/entities/tasks/flows-get)
- [List flows](/docs/entities/tasks/flows-list)
- [Update a flow](/docs/entities/tasks/flows-update)
- [Tasks](/docs/entities/tasks)
