Assign Phone Number By String
curl --request POST \
--url https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"phone_number": "<string>",
"friendly_name": "<string>",
"auto_sync": true
}
'import requests
url = "https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number"
payload = {
"phone_number": "<string>",
"friendly_name": "<string>",
"auto_sync": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({phone_number: '<string>', friendly_name: '<string>', auto_sync: true})
};
fetch('https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'phone_number' => '<string>',
'friendly_name' => '<string>',
'auto_sync' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number"
payload := strings.NewReader("{\n \"phone_number\": \"<string>\",\n \"friendly_name\": \"<string>\",\n \"auto_sync\": true\n}")
req, _ := http.NewRequest("POST", 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(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"phone_number\": \"<string>\",\n \"friendly_name\": \"<string>\",\n \"auto_sync\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"phone_number\": \"<string>\",\n \"friendly_name\": \"<string>\",\n \"auto_sync\": true\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"data": null
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Assistant Phone Numbers
Assign Phone Number by String
Assign a phone number to an assistant by phone number string.
Auto-syncs from Twilio if the number doesn’t exist locally and auto_sync is True. This is the recommended way to assign newly purchased Twilio numbers.
Args: assistant_id: ID of the assistant to assign the phone number to request: JSON request containing phone_number, friendly_name (optional), and auto_sync
POST
/
api
/
v1
/
assistants
/
{assistant_id}
/
phone-numbers
/
assign-by-number
Assign Phone Number By String
curl --request POST \
--url https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"phone_number": "<string>",
"friendly_name": "<string>",
"auto_sync": true
}
'import requests
url = "https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number"
payload = {
"phone_number": "<string>",
"friendly_name": "<string>",
"auto_sync": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({phone_number: '<string>', friendly_name: '<string>', auto_sync: true})
};
fetch('https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'phone_number' => '<string>',
'friendly_name' => '<string>',
'auto_sync' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number"
payload := strings.NewReader("{\n \"phone_number\": \"<string>\",\n \"friendly_name\": \"<string>\",\n \"auto_sync\": true\n}")
req, _ := http.NewRequest("POST", 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(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"phone_number\": \"<string>\",\n \"friendly_name\": \"<string>\",\n \"auto_sync\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/assistants/{assistant_id}/phone-numbers/assign-by-number")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"phone_number\": \"<string>\",\n \"friendly_name\": \"<string>\",\n \"auto_sync\": true\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"data": null
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}This endpoint assigns an available phone number from your organization to a specific assistant. The phone number must already exist within your organization’s pool of numbers and not be currently assigned to another assistant.
Path Parameters
assistant_id(string, required): The unique identifier of the assistant to whom the phone number will be assigned.
Request Body
phone_number(string, required): The phone number to assign, specified in E.164 format (e.g.,+15551234567).
Request
{
"phone_number": "+15551234567"
}
Response
A successful assignment will return the updated phone number object, which now includes theassistant_id.
Response
{
"id": "pn_1a2b3c4d5e6f7g8h",
"phone_number": "+15551234567",
"assistant_id": "asst_a1b2c3d4e5f67890",
"organization_id": "org_67890",
"created_at": "2023-10-26T11:00:00Z",
"updated_at": "2023-10-28T14:00:00Z"
}
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Body
application/json
Schema for assigning a phone number to an assistant.