> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.agentphone.to/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.agentphone.to/_mcp/server.

# Update Voice Routing

PATCH https://api.agentphone.ai/v1/numbers/{number_id}/voice-routing
Content-Type: application/json

Route a number's inbound calls.

`method` picks where calls to this number go:

- `"sip_trunk"`: deliver calls to one of your SIP trunks (`sipTrunkId`
  required). The number must be SIP-trunking eligible — see
  `sipTrunkingEligible` on the number response. iMessage numbers attach
  to a dedicated iMessage trunk (created with `"provider": "imessage"`;
  attaching is refused once a trunk already carries 100 numbers); other
  numbers attach to a standard trunk. With more than one number on a
  trunk, outbound calls over it must present one of the attached numbers
  as the caller ID.
- `"agent"`: restore hosted-agent answering (the number's assigned agent).
- `"ignore"`: drop inbound calls (not available for iMessage numbers).

For iMessage numbers the change converges in the background: the response
(and the number, on GET) carries `voiceRouting.routingState` `"pending"`
until it is live — the field disappears once applied — or `"error"` with
`routingError` when it could not be applied; re-sending the same request
retries a stuck change. Other numbers apply immediately.

Reference: https://docs.agentphone.to/api-reference/numbers/update-voice-routing-v-1-numbers-number-id-voice-routing-patch

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `number_id` (string, required)

### Body (application/json)

This endpoint expects an object.

- `method` (enum, required) — Where inbound calls to this number go.
  - Allowed values: `sip_trunk`, `agent`, `ignore`
- `sipTrunkId` (string, optional) — Trunk to deliver calls to; required when method is "sip_trunk".

## Response

### 200

Successful Response

- `success` (boolean, required)
- `voiceRouting` (VoiceRoutingInfo, required)

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### VoiceRoutingInfo

- `method` (string, required)
- `sipTrunkId` (string, optional, nullable)
- `sipTrunkName` (string, optional, nullable)
- `routingState` (string, optional, nullable)
- `routingError` (string, optional, nullable)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### ValidationErrorLocItems

- string
- integer

## Examples

**Request**

```json
{
  "method": "sip_trunk",
  "sipTrunkId": "trunk_id"
}
```

**Response**

```json
{
  "success": true,
  "voiceRouting": {
    "method": "string",
    "sipTrunkId": "string",
    "sipTrunkName": "string",
    "routingState": "string",
    "routingError": "string"
  }
}
```

**SDK Code**

```python numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
import requests

url = "https://api.agentphone.ai/v1/numbers/number_id/voice-routing"

payload = {
    "method": "sip_trunk",
    "sipTrunkId": "trunk_id"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
const url = 'https://api.agentphone.ai/v1/numbers/number_id/voice-routing';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"method":"sip_trunk","sipTrunkId":"trunk_id"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.agentphone.ai/v1/numbers/number_id/voice-routing"

	payload := strings.NewReader("{\n  \"method\": \"sip_trunk\",\n  \"sipTrunkId\": \"trunk_id\"\n}")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
require 'uri'
require 'net/http'

url = URI("https://api.agentphone.ai/v1/numbers/number_id/voice-routing")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"method\": \"sip_trunk\",\n  \"sipTrunkId\": \"trunk_id\"\n}"

response = http.request(request)
puts response.read_body
```

```java numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://api.agentphone.ai/v1/numbers/number_id/voice-routing")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"method\": \"sip_trunk\",\n  \"sipTrunkId\": \"trunk_id\"\n}")
  .asString();
```

```php numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.agentphone.ai/v1/numbers/number_id/voice-routing', [
  'body' => '{
  "method": "sip_trunk",
  "sipTrunkId": "trunk_id"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
using RestSharp;

var client = new RestClient("https://api.agentphone.ai/v1/numbers/number_id/voice-routing");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"method\": \"sip_trunk\",\n  \"sipTrunkId\": \"trunk_id\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift numbers_update_voice_routing_v1_numbers__number_id__voice_routing_patch_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "method": "sip_trunk",
  "sipTrunkId": "trunk_id"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.agentphone.ai/v1/numbers/number_id/voice-routing")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```