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

# Build call flows with the API

> Read, validate and replace a CloudTalk number's call flow, save drafts, restore versions, and set business hours and sounds with the v1 Call flows API.

Read and replace a number's call flow as one JSON document, check a change before it goes live, and undo it from the flow's versions:

```bash theme={"system"}
curl -i -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  https://api.cloudtalk.io/v1/numbers/600/call-flow
```

> [!WARNING]
>
> A saved flow answers the next call. [Validate](#check-a-change-before-you-save-it) a change first, or save it as a [draft](#save-a-draft-and-publish-it) for a person to publish. Keep the `versionId` of your read: [restoring](#undo-a-change) it undoes your save. If you did not keep it, or your read had `versionId: null`, find the version from before your save in [List call flow versions](https://help.cloudtalk.io/api-reference/call-flows/list-call-flow-versions.md) (for a first save, the `source: baseline` version).

The API key acts as a company admin. Number ids come from the [Numbers API](https://help.cloudtalk.io/guides/numbers/manage-with-api.md).

## Read a number's call flow

[Get a number's call flow](https://help.cloudtalk.io/api-reference/call-flows/get-a-numbers-call-flow.md) returns the flow and an `ETag` header that identifies this state of the flow's steps. Every live write needs it; a draft save may omit it. A shortened answer:

```json theme={"system"}
{
  "etag": "\"cf1-9fJ2kQx7Lr0aT3\"",
  "editable": true,
  "problems": [],
  "businessHours": { "active": false, "scope": null },
  "steps": [
    { "id": "5001", "type": "playback", "soundId": "79" }
  ],
  "versionId": "1834"
}
```

* `include=names` adds a name next to each id, such as `groupName`.
* To poll, send the `ETag` as `If-None-Match`: an unchanged flow answers `304`. The `ETag` covers the steps only, so `businessHours`, `versionId`, `editable` and `problems` can change while it stays the same.
* HTTP Request header values are never returned: a header reads `value: null` with `valueSet: true`.

### When a flow is not editable

A flow that reads `editable: false` cannot be sent back as it is. `problems` says why:

| Problem | Cause | What to do |
| - | - | - |
| `UNSUPPORTED_STEP_TYPE` | A step the API does not write, such as Conference, reads as `unsupported`. | Edit the flow in the Dashboard, or remove the step. |
| `MULTIPLE_FIRST_STEPS`, `ORPHAN_STEPS`, `MULTIPLE_NEXT_STEPS` | The stored steps do not form one tree. | Edit the flow in the Dashboard. |
| `STEP_NOT_ALLOWED_HERE` | The Dashboard saved a step where the API refuses it. | Move or remove the step. |
| `DANGLING_REFERENCE` | A step points at a deleted user, group, sound, voicemail box, voice agent or step (the field reads `null`), or a condition at a deleted contact field or contact tag (it keeps its `field` and `value`). | Set an existing record or remove the step, then send the corrected document to [Replace a number's call flow](https://help.cloudtalk.io/api-reference/call-flows/replace-a-numbers-call-flow.md). |
| `VOICE_AGENT_LOOKUP_FAILED` | Voice agents could not be read, so the step reads `voiceAgentId: null`. | Read the flow again later. |

When contact fields cannot be read, a custom field variable in an HTTP Request step may read in its stored id form, `{{contact.custom_fields.<id>}}`. It is accepted back as it is.

`editable: true` does not promise that an unchanged save succeeds: a flow saved in the Dashboard may break a [limit](#limits) (`422 VALIDATION.INVALID_FIELD`) or lack `ringSeconds` on a ring or redirect step with steps under "no answer" (`422 CALL_FLOWS.RING_SECONDS_REQUIRED`).

## Change a number's call flow

[Replace a number's call flow](https://help.cloudtalk.io/api-reference/call-flows/replace-a-numbers-call-flow.md) replaces every step. Send the document you read with your change, and the `ETag` of your read as `If-Match`. This flow plays a greeting, rings the Support group, then takes a voicemail:

```bash theme={"system"}
curl -i -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X PUT https://api.cloudtalk.io/v1/numbers/600/call-flow \
  -H "Content-Type: application/json" \
  -H 'If-Match: "cf1-9fJ2kQx7Lr0aT3"' \
  -d '{
    "steps": [
      { "type": "playback", "soundId": "79" },
      { "type": "ringGroup", "groupId": "611", "ringSeconds": 40,
        "onAnswered": [],
        "onNoAnswer": [
          { "type": "voicemail", "voicemailBoxId": "88",
            "emailNotification": "accountDefault", "attachRecording": "accountDefault" }
        ] }
    ],
    "note": "Ring Support after the greeting"
  }'
```

The response is the saved flow with its new `ETag`, `versionId` and `warnings`.

* **Ids.** Keep a step by sending its `id`; a step without one is new, and steps you leave out are deleted. Give a new step a `ref` when another step points at it, such as a Jump to `target`.
* **Round trip.** A document you read is accepted back, except for [a flow that is not editable](#when-a-flow-is-not-editable). Read-only fields are ignored; any other unknown field is `400 VALIDATION.INVALID_BODY`.
* **Secrets.** Send an HTTP Request header without `value` to keep its stored value. Put credentials in headers, not in the URL or body.
* **Other numbers.** Deleting a step also deletes the Jump to steps in other numbers that point at it.

**Two writers.** The `ETag` is a hash of the stored steps. A change to them moves it, such as a Dashboard save or deleting a group the flow uses; a change that returns them to your read, such as a restore, brings it back. On a `412`, read the flow again, apply your change and retry.

| Status | Code | When |
| - | - | - |
| `412` | `CALL_FLOWS.ETAG_MISMATCH` | The stored steps differ from the read whose `ETag` you sent. |
| `413` | `VALIDATION.INVALID_BODY` | The body is over 1 MiB. |
| `422` | `CALL_FLOWS.RING_SECONDS_REQUIRED` | A ring or redirect step has steps in `onNoAnswer` but no `ringSeconds`. |
| `422` | `VALIDATION.INVALID_FIELD`, `CALL_FLOWS.*` | A step is not valid. `target` is a JSON pointer such as `/steps/1/groupId`; `details` lists every problem. |
| `428` | `CALL_FLOWS.IF_MATCH_REQUIRED` | `If-Match` is missing or `*`. |
| `502` | `CALL_FLOWS.UPSTREAM_UNAVAILABLE` | Voice agents could not be checked. Retry. |

After a `500` on a call flow write, read the flow before you retry. Do not retry with the same `If-Match`: if a later edit returned the steps to the content of your read, the retry would overwrite that edit. A retried draft save may store a second draft.

### Step types

[List call flow step types](https://help.cloudtalk.io/api-reference/call-flows/list-call-flow-step-types.md) gives the 18 step types the API writes, each with its fields as JSON Schema and whether your plan allows it.

* Fax must be the only step of the flow.
* After Voicemail, only HTTP Request, Mark Call as Resolved, Condition Splitter, Day/Time Splitter and Jump to may follow.
* Jump to may loop back when the loop has a step that waits for the caller, such as an IVR menu or a ring step.
* Day/Time Splitter times are in the account time zone. With no match and no `otherwise`, the call is hung up.

### Limits

* **Size limits.** A call flow has at most 200 steps and a body of at most 1 MiB (`413 VALIDATION.INVALID_BODY`). A step `name` takes up to 100 characters, a Collect Input `pattern` up to 255. An HTTP Request step takes a `url` up to 2,048 characters, up to 50 headers (name up to 256 characters, value up to 8,192) and up to 50 body fields (key up to 255 characters, value up to 8,192). A Condition Splitter takes up to 50 branches of up to 50 conditions, a Day/Time Splitter up to 50 branches. A step over 64 KB, or a field over its limit, is `422 VALIDATION.INVALID_FIELD` at that step or field. The Dashboard does not enforce these limits.

## Check a change before you save it

[Validate a call flow](https://help.cloudtalk.io/api-reference/call-flows/validate-a-call-flow.md) runs every check of a save without saving, and answers `200` even when the document has errors:

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/numbers/600/call-flow/validate \
  -H "Content-Type: application/json" \
  -H 'If-Match: "cf1-9fJ2kQx7Lr0aT3"' \
  -d @flow.json
```

```json theme={"system"}
{
  "valid": false,
  "errors": [ { "code": "CALL_FLOWS.UNKNOWN_GROUP", "message": "Group 568 is not in your account.", "target": "/steps/1/groupId" } ],
  "warnings": [],
  "changes": { "added": [], "updated": [], "removed": [ { "id": "5012", "type": "ringUser" } ], "otherNumbers": [] }
}
```

* `errors` lists what a save would refuse, including a stale `If-Match` as `CALL_FLOWS.ETAG_MISMATCH`.
* `warnings` never stop a save. `BUSINESS_HOURS_APPLY` means business hours run before the flow.
* `changes` previews the steps a save adds, updates and removes.
* With `VOICE_AGENT_CHECK_SKIPPED` in `warnings`, voice agents were not checked, so a save may still answer `502`.

## Save a draft and publish it

Save with `?draft=true` to keep a change for a person to approve. Calls keep using the live flow. The draft passes every check of a save, and the response is `201` with `live: false` and the draft's `versionId`.

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X PUT "https://api.cloudtalk.io/v1/numbers/600/call-flow?draft=true" \
  -H "Content-Type: application/json" \
  -H 'If-Match: "cf1-9fJ2kQx7Lr0aT3"' \
  -d @flow.json
```

`If-Match` is optional for a draft. Send the `ETag` of your read and keep it for the publish: the draft's own `etag` is the live flow's, which may be newer.

[Publish a call flow draft](https://help.cloudtalk.io/api-reference/call-flows/publish-a-call-flow-draft.md) by the draft's `versionId`, with the `ETag` of your read. Avoid `latest-draft`: it names the newest draft when the request arrives, which may not be the approved one.

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/numbers/600/call-flow/versions/1836/publish \
  -H "Content-Type: application/json" \
  -H 'If-Match: "cf1-9fJ2kQx7Lr0aT3"' \
  -d '{"note": "Approved by the support lead"}'
```

A draft never overwrites a later save. When the live flow's steps differ from the steps the draft was saved on, publishing is `412` whatever `ETag` you send: read the live flow, save the draft again on it, and publish the new draft. A number keeps up to 10 drafts, oldest dropped first. A draft over 15 MiB is refused with `422`.

Publishing a version that is not a draft is `409 CALL_FLOWS.NOT_A_DRAFT`.

## Undo a change

[Restore a call flow version](https://help.cloudtalk.io/api-reference/call-flows/restore-a-call-flow-version.md) makes a version live again, with the checks of a save:

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/numbers/600/call-flow/versions/1834/restore \
  -H "Content-Type: application/json" \
  -H 'If-Match: "cf1-Qe81mZp04Kd2Yt"' \
  -d '{"note": "Back to the previous menu"}'
```

[List call flow versions](https://help.cloudtalk.io/api-reference/call-flows/list-call-flow-versions.md) shows who changed the flow (`actor`), from where (`source`) and why (`note`). Besides an id, restore takes `live`, `latest` and `latest-draft`.

* Every save keeps a version, from the Dashboard or the API. A number keeps its latest 50 versions and up to 10 drafts. The `baseline` is always kept: the flow as it was before versions were introduced.
* When a number is released, its versions are deleted with it. A number whose flow you delete keeps its versions.
* A save whose version would be over 15 MiB keeps no version. Deleting a user or group in the Dashboard, a plan downgrade and a new number's default step write none either.

Steps the live flow still has, with the same type, keep their `id`; the others come back as new steps. Jump to steps that a change deleted in other numbers do not come back (warning `JUMP_TO_NOT_RESTORED`).

**Header values.** Versions keep HTTP Request header values only for a while. Drafts always keep them. Any other version keeps them while it is one of the number's 5 newest versions (drafts not counted) or less than 7 days old; after that, the next save of the flow removes them. A restore fills a missing value from the live step with the same `id` and header `name`. When the live flow has none, the restore is `422 CALL_FLOWS.HEADER_VALUE_REQUIRED` and changes nothing: read the version, set those header values in its steps, and save it with [Replace a number's call flow](https://help.cloudtalk.io/api-reference/call-flows/replace-a-numbers-call-flow.md). A step the live flow no longer has goes without its `id`, as a new step.

| Status | Code | When |
| - | - | - |
| `404` | `CALL_FLOWS.VERSION_NOT_FOUND` | No such version. |
| `422` | `CALL_FLOWS.HEADER_VALUE_REQUIRED` | The version no longer keeps a header value and the live flow has none. `details` names each step and header. |
| `422` | `CALL_FLOWS.UNKNOWN_*` | The version names a record deleted since, such as a user. |
| `422` | `VALIDATION.INVALID_FIELD` | The version has steps the API cannot represent. Open it in the Dashboard. |

## Delete a number's call flow

[Delete a number's call flow](https://help.cloudtalk.io/api-reference/call-flows/delete-a-numbers-call-flow.md) removes every step (send `If-Match`). From the next call, calls to the number are hung up straight away; business hours still apply. Jump to steps in other numbers that pointed into the flow are deleted. The number keeps its versions, so a restore undoes the deletion.

## Set business hours

Outside business hours, a call gets the closed action instead of the call flow. A flow's `businessHours` shows whether hours apply and whose.

* [Company business hours](https://help.cloudtalk.io/api-reference/business-hours/replace-company-business-hours.md) apply to every number that uses them, while `enabled` is `true`.
* [A number's own business hours](https://help.cloudtalk.io/api-reference/business-hours/replace-a-numbers-business-hours.md) apply instead while `useOwnHours` is `true`. Send `useOwnHours: false` alone to return to the company hours; the number's own hours are kept.

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X PUT https://api.cloudtalk.io/v1/numbers/1201/business-hours \
  -H "Content-Type: application/json" \
  -d '{
    "useOwnHours": true,
    "openingHours": [ { "day": "monday", "from": "08:00", "to": "17:00" } ],
    "specialDates": [ { "date": "2026-11-23", "closedAllDay": true } ],
    "holidaysClosed": true,
    "closedAction": { "type": "redirect", "phoneNumber": "+12025550172" }
  }'
```

* Times are `HH:mm` in the account time zone. A special date overrides the weekday and holidays: closed all day, or open from `from` to `to`. `holidaysClosed` closes on the public holidays of the number's country ([List public holidays](https://help.cloudtalk.io/api-reference/business-hours/list-public-holidays.md)).
* `closedAction` is `redirect`, `voicemail`, `sound` or `soundThenVoicemail`. A replace that sets hours, such as one with `useOwnHours: true`, needs one.
* A replace takes up to 100 opening intervals and 1,000 special dates, and applies to the next call. Business hours keep no versions.
* Hours never saved read with empty lists and `closedAction: null`, and are accepted back as they are.
* A closed action whose `soundId`, `voicemailBoxId` or `phoneNumber` reads `null` is accepted back only with the hours off (`enabled: false` or `useOwnHours: false`) and with `openingHours`, `specialDates`, `holidaysClosed` and `closedAction` as a read returns them now. The hours then switch off and the stored closed action is kept. Otherwise the `null` is `422 VALIDATION.INVALID_FIELD`.

| Status | Code | When |
| - | - | - |
| `409` | `CONFLICT` | Another change of the same hours is running. Retry. |
| `422` | `BUSINESS_HOURS.OVERLAPPING_HOURS` | Two intervals of the same day overlap. |
| `504` | `TIMEOUT` | No answer within 30 seconds. The change may still complete: read the hours before you retry. |

### Redirect all calls in an emergency

1. Read the number's hours with [Get a number's business hours](https://help.cloudtalk.io/api-reference/business-hours/get-a-numbers-business-hours.md) and keep the object: it is your way back.
2. Replace them as in the example above: today as a special date with `closedAllDay: true`, and a `redirect` closed action.
3. When it is over, send the object you kept, as it is, even for hours never saved (`useOwnHours: false`, `closedAction: null`). If the kept `closedAction` has `soundId`, `voicemailBoxId` or `phoneNumber` `null`, set a value in it first: your emergency change replaced the stored hours, and with `useOwnHours: true` a save always needs a value.

## Add a sound

Steps and closed actions play sounds. [Create a sound](https://help.cloudtalk.io/api-reference/sounds/create-a-sound.md) from text, with a voice from [List text-to-speech voices](https://help.cloudtalk.io/api-reference/sounds/list-text-to-speech-voices.md), or from an MP3 file up to 8 MB:

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/sounds \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: holiday-greeting-2026" \
  -d '{"name": "Holiday greeting", "text": "Thank you for calling. Our office is closed today.", "voice": "rachel", "language": "en"}'
```

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/sounds \
  -F name="Main menu" \
  -F file=@main-menu.mp3
```

A new sound has `status: processing`, then turns `ready`, or `failed` when it cannot be converted: check `status` with [Get a sound](https://help.cloudtalk.io/api-reference/sounds/get-a-sound.md). A flow may use it at once (validate warns `SOUND_PROCESSING`). Its `audioUrl` expires after about 5 minutes. A retry with the same `Idempotency-Key` and body returns the first answer for 24 hours.

| Status | Code | When |
| - | - | - |
| `409` | `CONFLICT` | A request with the same `Idempotency-Key` is still running. |
| `409` | `SOUNDS.IN_USE` | [Delete a sound](https://help.cloudtalk.io/api-reference/sounds/delete-a-sound.md): the sound is in use. `details` lists each kind of record that uses it. |
| `422` | `VALIDATION.INVALID_FIELD` | The name is not 1 to 60 characters or contains `<` or `>`, or the file is not MP3 or is over 8 MB. |
| `422` | `IDEMPOTENCY.KEY_REUSED` | The `Idempotency-Key` was used with a different request. |
| `429` | `SOUNDS.TEXT_TO_SPEECH_LIMIT` | Over your account's text-to-speech limit. Retry after `Retry-After`. |
| `504` | `TIMEOUT` | No answer within 45 seconds. Retry with the same `Idempotency-Key`. |

[List voicemail boxes](https://help.cloudtalk.io/api-reference/call-flows/list-voicemail-boxes.md) gives the `voicemailBoxId` values.

## Errors

* An unknown number id is `404 CALL_FLOWS.NUMBER_NOT_FOUND` (`BUSINESS_HOURS.NUMBER_NOT_FOUND` on business hours).
* `403` means your plan lacks a feature: `BUSINESS_HOURS.NOT_IN_PLAN`, `BUSINESS_HOURS.VOICEMAIL_NOT_IN_PLAN` (a voicemail closed action on a plan without human agents), `SOUNDS.NOT_IN_PLAN`, `CALL_FLOWS.STEP_TYPE_NOT_IN_PLAN`.
* The call flow operations answer `403 FORBIDDEN` when your account is not active, and `409 CALL_FLOWS.NUMBER_NOT_READY` when the number has no routing record: contact support.
* [List voicemail boxes](https://help.cloudtalk.io/api-reference/call-flows/list-voicemail-boxes.md) answers `504 TIMEOUT` after 30 seconds. Retry.
* When you contact support, quote `requestId`, which is the request's `X-Request-ID`.

[Error codes](https://help.cloudtalk.io/guides/error-codes.md) covers the error shape, `401`, `429` and `500`.


## Related topics

- [CloudTalk API HTTP Error Codes: Causes and Resolutions](https://help.cloudtalk.io/guides/error-codes.md)
- [List call flow step types](https://help.cloudtalk.io/api-reference/call-flows/list-call-flow-step-types.md)
- [Quickstart: Make Your First CloudTalk REST API Call](https://help.cloudtalk.io/guides/quickstart.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.