> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 更新电话号码

PATCH https://api.elevenlabs.io/v1/convai/phone-numbers/{phone_number_id}
Content-Type: application/json

更新分配给电话号码的智能体。

Reference: https://elevenlabs.io/docs/api-reference/phone-numbers/update

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Path parameters

- `phone_number_id` (string, required) — 电话号码 ID。导入电话号码时会返回此值。

### Body (application/json)

This endpoint expects an UpdatePhoneNumberRequest.

- `agent_id` (string, optional, nullable)
- `label` (string, optional, nullable)
- `inbound_trunk_config` (InboundSIPTrunkConfigRequestModel, optional, nullable)
- `outbound_trunk_config` (OutboundSIPTrunkConfigRequestModel, optional, nullable)
- `livekit_stack` (enum, optional, nullable, default: standard)
  - Allowed values: `standard`, `static`
- `store_sip_messages` (boolean, optional, nullable)
- `environment` (string, optional, nullable) — 调用此号码时用于解析环境变量的环境。
- `branch_id` (string, optional, nullable) — 呼叫此号码时使用的智能体分支。

## Response

### 200

成功响应

- `conversational_ai_phone_numbers_update_Response_200`
  - `provider`: `twilio` (GetPhoneNumberTwilioResponseModel)
    - `label` (string, required) — 电话号码标签
    - `phone_number` (string, required) — 电话号码
    - `phone_number_id` (string, required) — 电话号码的 ID
    - `assigned_agent` (PhoneNumberAgentInfo, optional, nullable) — 分配给该电话号码的智能体
    - `supports_inbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼入电话。
    - `supports_outbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼出电话。
  - `provider`: `exotel` (GetPhoneNumberExotelResponseModel)
    - `label` (string, required) — 电话号码标签
    - `phone_number` (string, required) — 电话号码
    - `phone_number_id` (string, required) — 电话号码的 ID
    - `assigned_agent` (PhoneNumberAgentInfo, optional, nullable) — 分配给该电话号码的智能体
    - `supports_inbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼入电话。
    - `supports_outbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼出电话。
  - `provider`: `sip_trunk` (GetPhoneNumberSIPTrunkResponseModel)
    - `label` (string, required) — 电话号码标签
    - `livekit_stack` (enum, required, default: standard) — 此号码使用的 Livekit 栈类型。
      - Allowed values: `standard`, `static`
    - `phone_number` (string, required) — 电话号码
    - `phone_number_id` (string, required) — 电话号码的 ID
    - `assigned_agent` (PhoneNumberAgentInfo, optional, nullable) — 分配给该电话号码的智能体
    - `inbound_trunk` (GetPhoneNumberInboundSIPTrunkConfigResponseModel, optional, nullable) — Configuration of the Inbound SIP trunk - if configured.
    - `outbound_trunk` (GetPhoneNumberOutboundSIPTrunkConfigResponseModel, optional, nullable) — Configuration of the Outbound SIP trunk - if configured.
    - `store_sip_messages` (boolean, optional, default: true) — 是否存储此电话号码的 SIP 消息。
    - `provider_config` (GetPhoneNumberOutboundSIPTrunkConfigResponseModel, optional, nullable, deprecated) — 电话号码的 SIP 中继配置详情
    - `supports_inbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼入电话。
    - `supports_outbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼出电话。

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### InboundSIPTrunkConfigRequestModel

- `allowed_addresses` (list of string, optional, nullable) — 允许使用中继的 IP 地址列表。列表中的每项可以是单个 IP 地址，或表示 CIDR 块的无类别域间路由表示法。
- `allowed_numbers` (list of string, optional, nullable) — 允许使用中继的电话号码列表。
- `media_encryption` (enum, optional, default: allowed) — 是否加密媒体数据（数据层）。
  - Allowed values: `disabled`, `allowed`, `required`
- `credentials` (SIPTrunkCredentialsRequestModel, optional, nullable) — 可选的摘要式身份验证凭据（用户名/密码）。
- `remote_domains` (list of string, optional, nullable) — 用于验证 TLS 证书的远程 SIP 服务器域名。
- `attributes_to_headers` (map from string to string, optional) — 用于 attributes_to_headers 的动态变量名称到请求头名称的映射

### OutboundSIPTrunkConfigRequestModel

- `address` (string, required) — 发送 SIP INVITE 的主机名或 IP。
- `transport` (enum, optional, default: auto) — 用于 SIP 传输的协议（信令层）。
  - Allowed values: `auto`, `udp`, `tcp`, `tls`
- `media_encryption` (enum, optional, default: allowed) — 是否加密媒体数据（数据层）。
  - Allowed values: `disabled`, `allowed`, `required`
- `headers` (map from string to string, optional) — INVITE 请求的 SIP X-* 标头。这些标头会原样发送，可能有助于识别此通通话。
- `attributes_to_headers` (map from string to string, optional) — 用于 attributes_to_headers 的动态变量名称到请求头名称的映射
- `credentials` (SIPTrunkCredentialsRequestModel, optional, nullable) — 可选的摘要式认证凭据（用户名/密码）。未提供时，默认使用 ACL 认证。
- `enabled_codecs` (list of enum, optional) — 应在外呼 SDP 中提供的媒体编解码器。为空时，将提供所有支持的编解码器。
  - Allowed values: `G722/8000`, `PCMU/8000`, `PCMA/8000`

### PhoneNumberAgentInfo

- `agent_id` (string, required) — 智能体 ID
- `agent_name` (string, required) — 智能体名称
- `environment` (string, optional, nullable) — 调用此号码时用于解析环境变量的环境。
- `branch_id` (string, optional, nullable) — 呼叫此号码时使用的智能体分支。

### GetPhoneNumberInboundSIPTrunkConfigResponseModel

- `allowed_addresses` (list of string, required) — 允许使用中继的 IP 地址列表。列表中的每项可以是单个 IP 地址，或表示 CIDR 块的无类别域间路由表示法。
- `allowed_numbers` (list of string, required, nullable) — 允许使用中继的电话号码列表。
- `media_encryption` (enum, required, default: allowed)
  - Allowed values: `disabled`, `allowed`, `required`
- `has_auth_credentials` (boolean, required) — 是否已配置身份验证凭据
- `username` (string, optional, nullable) — SIP 中继用户名（如有）
- `remote_domains` (list of string, optional, nullable) — 用于验证 TLS 证书的远程 SIP 服务器域名。
- `attributes_to_headers` (map from string to string, optional) — 用于 attributes_to_headers 的动态变量名称到请求头名称的映射

### GetPhoneNumberOutboundSIPTrunkConfigResponseModel

电话号码的 SIP 中继配置详情

- `address` (string, required) — 发送 SIP INVITE 的主机名或 IP
- `transport` (enum, required, default: auto) — 用于 SIP 传输的协议
  - Allowed values: `auto`, `udp`, `tcp`, `tls`
- `media_encryption` (enum, required, default: allowed) — 是否加密媒体数据（数据层）。
  - Allowed values: `disabled`, `allowed`, `required`
- `has_auth_credentials` (boolean, required) — 是否已配置身份验证凭据
- `headers` (map from string to string, optional) — INVITE 请求的 SIP 标头
- `attributes_to_headers` (map from string to string, optional) — 用于 attributes_to_headers 的动态变量名称到请求头名称的映射
- `username` (string, optional, nullable) — SIP 中继用户名（如有）
- `has_outbound_trunk` (boolean, optional, default: false) — 是否已配置 LiveKit SIP 出站中继
- `enabled_codecs` (list of enum, optional) — 外呼 SDP 中提供的媒体编解码器。为空时，将提供所有支持的编解码器。
  - Allowed values: `G722/8000`, `PCMU/8000`, `PCMA/8000`

### ValidationError

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

### SIPTrunkCredentialsRequestModel

- `username` (string, required) — SIP 中继用户名
- `password` (string, optional, nullable) — SIP 中继密码：未指定则保持不变

### ValidationErrorLocItems

- string
- integer

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "provider": "twilio",
  "label": "Customer Support",
  "phone_number": "+1234567890",
  "phone_number_id": "phone_123"
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT"

payload = {}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT';
const options = {method: 'PATCH', headers: {'Content-Type': 'application/json'}, body: '{}'};

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

```go
package main

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

func main() {

	url := "https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT"

	payload := strings.NewReader("{}")

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

	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
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT")

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

request = Net::HTTP::Patch.new(url)
request["Content-Type"] = 'application/json'
request.body = "{}"

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

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

HttpResponse<String> response = Unirest.patch("https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT', [
  'body' => '{}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/convai/phone-numbers/TeaqRRdTcIfIu2i7BYfT")! 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()
```