---
title: "Buy a phone number and optionally configure SMS and Voice"
description: "A successful purchase returns HTTP 200 even if setup fails. Inspect setupErrors; never retry the purchase to repair setup. SMS uses the existing workspace SMS route; Voice uses the existing Voice provisioning endpoint."
---

> Documentation Index
> Fetch the complete documentation index at: https://developer.channelautomations.com/llms.txt
> Use this file to discover all available pages before exploring further.

Path: Channel Automation API › Twilio

`POST /api/twilio/purchase-number`

A successful purchase returns HTTP 200 even if setup fails. Inspect setupErrors; never retry the purchase to repair setup. SMS uses the existing workspace SMS route; Voice uses the existing Voice provisioning endpoint.

## Authentication

- `BearerAuth`, http, header `Authorization`, format `JWT`

## Header parameters

- `x-workspace-id` (`post/api/twilio/purchase-number.header.x-workspace-id`; string, required)

## Request body

_Required._

- `workspaceId` (`post/api/twilio/purchase-number.workspaceId`; string, required)
- `phoneNumber` (`post/api/twilio/purchase-number.phoneNumber`; string, required) — E.164 phone number
- `messagingServiceSid` (`post/api/twilio/purchase-number.messagingServiceSid`; string, optional) — Optional approved A2P messaging service; requires SMS setup
- `configure` (`post/api/twilio/purchase-number.configure`; object, optional)
  - `sms` (`post/api/twilio/purchase-number.configure.sms`; boolean, optional)
    - default `false`
  - `voice` (`post/api/twilio/purchase-number.configure.voice`; boolean, optional)
    - default `false`

## Example request

```json
{
  "workspaceId": "string",
  "phoneNumber": "string",
  "messagingServiceSid": "string",
  "configure": {
    "sms": false,
    "voice": false
  }
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://api.channelautomation.com/api/twilio/purchase-number \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-workspace-id: string' \
  --data '
{
  "workspaceId": "string",
  "phoneNumber": "string",
  "messagingServiceSid": "string",
  "configure": {
    "sms": false,
    "voice": false
  }
}
'
```

### TypeScript

```typescript
const url = 'https://api.channelautomation.com/api/twilio/purchase-number';
const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-workspace-id': 'string',
    Authorization: 'Bearer <token>'
  },
  body: JSON.stringify({
    workspaceId: 'string',
    phoneNumber: 'string',
    messagingServiceSid: 'string',
    configure: {sms: false, voice: false}
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.channelautomation.com/api/twilio/purchase-number"

payload = {
    "workspaceId": "string",
    "phoneNumber": "string",
    "messagingServiceSid": "string",
    "configure": {
        "sms": False,
        "voice": False
    }
}
headers = {
    "Content-Type": "application/json",
    "x-workspace-id": "string",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Purchased; configuredChannels, a2pAttachment and setupErrors describe setup results

### 400

Invalid purchase input

### 401

Authentication required

### 403

Workspace does not match authorized context

### 404

Twilio configuration missing

### 409

Selected campaign is no longer approved; no attachment attempted

### 502

Purchase not confirmed; check Twilio before retrying

### 503

Campaign approval could not be checked before purchase


Source: https://developer.channelautomations.com/api/post-api-twilio-purchase-number/index.md
