Skip to contentSkip to navigationSkip to topbar
On this page

Trunk Resource


The Trunk resource represents a SIP Trunk in your Twilio account. A Trunk can have associated Credential Lists, IP Access Control Lists, Origination URLs, and Phone Numbers.

To learn how to create and use SIP Trunks, check out our getting started guide.


Trunk Properties

trunk-properties page anchor
Property nameTypeRequiredDescriptionChild properties
account_sidSID<AC>

Optional

Not PII

The SID of the Account that created the Trunk resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

domain_namestring

Optional

The unique address you reserve on Twilio to which you route your SIP traffic. Domain names can contain letters, digits, and - and must end with pstn.twilio.com. See Termination Settings for more information.


disaster_recovery_methodenum<http-method>

Optional

The HTTP method we use to call the disaster_recovery_url. Can be: GET or POST.

Possible values:
GETPOST

disaster_recovery_urlstring<uri>

Optional

PII MTL: 30 days

The URL we call using the disaster_recovery_method if an error occurs while sending SIP traffic towards the configured Origination URL. We retrieve TwiML from this URL and execute the instructions like any other normal TwiML call. See Disaster Recovery for more information.


friendly_namestring

Optional

The string that you assigned to describe the resource.


secureboolean

Optional

Whether Secure Trunking is enabled for the trunk. If enabled, all calls going through the trunk will be secure using SRTP for media and TLS for signaling. If disabled, then RTP will be used for media. See Secure Trunking for more information.


recordingobject

Optional

The recording settings for the trunk. Can be: do-not-record, record-from-ringing, record-from-answer. If set to record-from-ringing or record-from-answer, all calls going through the trunk will be recorded. The only way to change recording parameters is on a sub-resource of a Trunk after it has been created. e.g./Trunks/[Trunk_SID]/Recording -XPOST -d'Mode=record-from-answer'. See Recording for more information.


transfer_modeenum<string>

Optional

The call transfer settings for the trunk. Can be: enable-all, sip-only and disable-all. See Transfer for more information.

Possible values:
disable-allenable-allsip-only

transfer_caller_idenum<string>

Optional

Caller Id for transfer target. Can be: from-transferee (default) or from-transferor.

Possible values:
from-transfereefrom-transferor

cnam_lookup_enabledboolean

Optional

Whether Caller ID Name (CNAM) lookup is enabled for the trunk. If enabled, all inbound calls to the SIP Trunk from the United States and Canada automatically perform a CNAM Lookup and display Caller ID data on your phone. See CNAM Lookups for more information.


auth_typestring

Optional

The types of authentication mapped to the domain. Can be: IP_ACL and CREDENTIAL_LIST. If both are mapped, the values are returned in a comma delimited list. If empty, the domain will not receive any traffic.


auth_type_setarray[string]

Optional

Reserved.


date_updatedstring<date-time>

Optional

The date and time in GMT when the resource was last updated specified in RFC 2822(link takes you to an external page) format.


sidSID<TK>

Optional

The unique string that we created to identify the Trunk resource.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34

urlstring<uri>

Optional

The absolute URL of the resource.


linksobject<uri-map>

Optional

The URLs of related resources.


POST https://trunking.twilio.com/v1/Trunks

Request body parameters

request-body-parameters page anchor
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
FriendlyNamestring

Optional

A descriptive string that you create to describe the resource. It can be up to 64 characters long.


DomainNamestring

Optional

The unique address you reserve on Twilio to which you route your SIP traffic. Domain names can contain letters, digits, and - and must end with pstn.twilio.com. See Termination Settings for more information.


DisasterRecoveryUrlstring<uri>

Optional

The URL we should call using the disaster_recovery_method if an error occurs while sending SIP traffic towards the configured Origination URL. We retrieve TwiML from the URL and execute the instructions like any other normal TwiML call. See Disaster Recovery for more information.


DisasterRecoveryMethodenum<http-method>

Optional

The HTTP method we should use to call the disaster_recovery_url. Can be: GET or POST.

Possible values:
GETPOST

TransferModeenum<string>

Optional

The call transfer settings for the trunk. Can be: enable-all, sip-only and disable-all. See Transfer for more information.

Possible values:
disable-allenable-allsip-only

Secureboolean

Optional

Whether Secure Trunking is enabled for the trunk. If enabled, all calls going through the trunk will be secure using SRTP for media and TLS for signaling. If disabled, then RTP will be used for media. See Secure Trunking for more information.


CnamLookupEnabledboolean

Optional

Whether Caller ID Name (CNAM) lookup should be enabled for the trunk. If enabled, all inbound calls to the SIP Trunk from the United States and Canada automatically perform a CNAM Lookup and display Caller ID data on your phone. See CNAM Lookups for more information.


TransferCallerIdenum<string>

Optional

Caller Id for transfer target. Can be: from-transferee (default) or from-transferor.

Possible values:
from-transfereefrom-transferor
Create TrunkLink to code sample: Create Trunk
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createTrunk() {
11
const trunk = await client.trunking.v1.trunks.create();
12
13
console.log(trunk.accountSid);
14
}
15
16
createTrunk();

Output

1
{
2
"sid": "TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"domain_name": "test.pstn.twilio.com",
5
"disaster_recovery_method": "POST",
6
"disaster_recovery_url": "http://disaster-recovery.com",
7
"friendly_name": "friendly_name",
8
"secure": false,
9
"cnam_lookup_enabled": false,
10
"recording": {
11
"mode": "do-not-record",
12
"trim": "do-not-trim"
13
},
14
"transfer_mode": "disable-all",
15
"transfer_caller_id": "from-transferee",
16
"auth_type": "",
17
"auth_type_set": [],
18
"date_created": "2015-01-02T11:23:45Z",
19
"date_updated": "2015-01-02T11:23:45Z",
20
"url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"links": {
22
"origination_urls": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/OriginationUrls",
23
"credential_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/CredentialLists",
24
"ip_access_control_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IpAccessControlLists",
25
"phone_numbers": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers"
26
}
27
}

GET https://trunking.twilio.com/v1/Trunks/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<TK>required

The unique string that we created to identify the Trunk resource to fetch.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchTrunk() {
11
const trunk = await client.trunking.v1
12
.trunks("TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.fetch();
14
15
console.log(trunk.accountSid);
16
}
17
18
fetchTrunk();

Output

1
{
2
"sid": "TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"domain_name": "test.pstn.twilio.com",
5
"disaster_recovery_method": "POST",
6
"disaster_recovery_url": "http://disaster-recovery.com",
7
"friendly_name": "friendly_name",
8
"secure": false,
9
"cnam_lookup_enabled": false,
10
"recording": {
11
"mode": "do-not-record",
12
"trim": "do-not-trim"
13
},
14
"transfer_mode": "disable-all",
15
"transfer_caller_id": "from-transferor",
16
"auth_type": "",
17
"auth_type_set": [],
18
"date_created": "2015-01-02T11:23:45Z",
19
"date_updated": "2015-01-02T11:23:45Z",
20
"url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"links": {
22
"origination_urls": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/OriginationUrls",
23
"credential_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/CredentialLists",
24
"ip_access_control_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IpAccessControlLists",
25
"phone_numbers": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers"
26
}
27
}

Read multiple Trunk resources

read-multiple-trunk-resources page anchor
GET https://trunking.twilio.com/v1/Trunks

Property nameTypeRequiredPIIDescription
PageSizeinteger

Optional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

Pageinteger

Optional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstring

Optional

The page token. This is provided by the API.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listTrunk() {
11
const trunks = await client.trunking.v1.trunks.list({ limit: 20 });
12
13
trunks.forEach((t) => console.log(t.accountSid));
14
}
15
16
listTrunk();

Output

1
{
2
"meta": {
3
"first_page_url": "https://trunking.twilio.com/v1/Trunks?PageSize=50&Page=0",
4
"url": "https://trunking.twilio.com/v1/Trunks?PageSize=50&Page=0",
5
"page_size": 50,
6
"key": "trunks",
7
"next_page_url": null,
8
"page": 0,
9
"previous_page_url": null
10
},
11
"trunks": [
12
{
13
"sid": "TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"domain_name": "test.pstn.twilio.com",
16
"disaster_recovery_method": "POST",
17
"disaster_recovery_url": "http://disaster-recovery.com",
18
"friendly_name": "friendly_name",
19
"secure": false,
20
"cnam_lookup_enabled": false,
21
"recording": {
22
"mode": "do-not-record",
23
"trim": "do-not-trim"
24
},
25
"transfer_mode": "disable-all",
26
"transfer_caller_id": "from-transferee",
27
"auth_type": "",
28
"auth_type_set": [],
29
"date_created": "2015-01-02T11:23:45Z",
30
"date_updated": "2015-01-02T11:23:45Z",
31
"url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
32
"links": {
33
"origination_urls": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/OriginationUrls",
34
"credential_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/CredentialLists",
35
"ip_access_control_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IpAccessControlLists",
36
"phone_numbers": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers"
37
}
38
}
39
]
40
}

POST https://trunking.twilio.com/v1/Trunks/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<TK>required

The unique string that we created to identify the OriginationUrl resource to update.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
FriendlyNamestring

Optional

A descriptive string that you create to describe the resource. It can be up to 64 characters long.


DomainNamestring

Optional

The unique address you reserve on Twilio to which you route your SIP traffic. Domain names can contain letters, digits, and - and must end with pstn.twilio.com. See Termination Settings for more information.


DisasterRecoveryUrlstring<uri>

Optional

The URL we should call using the disaster_recovery_method if an error occurs while sending SIP traffic towards the configured Origination URL. We retrieve TwiML from the URL and execute the instructions like any other normal TwiML call. See Disaster Recovery for more information.


DisasterRecoveryMethodenum<http-method>

Optional

The HTTP method we should use to call the disaster_recovery_url. Can be: GET or POST.

Possible values:
GETPOST

TransferModeenum<string>

Optional

The call transfer settings for the trunk. Can be: enable-all, sip-only and disable-all. See Transfer for more information.

Possible values:
disable-allenable-allsip-only

Secureboolean

Optional

Whether Secure Trunking is enabled for the trunk. If enabled, all calls going through the trunk will be secure using SRTP for media and TLS for signaling. If disabled, then RTP will be used for media. See Secure Trunking for more information.


CnamLookupEnabledboolean

Optional

Whether Caller ID Name (CNAM) lookup should be enabled for the trunk. If enabled, all inbound calls to the SIP Trunk from the United States and Canada automatically perform a CNAM Lookup and display Caller ID data on your phone. See CNAM Lookups for more information.


TransferCallerIdenum<string>

Optional

Caller Id for transfer target. Can be: from-transferee (default) or from-transferor.

Possible values:
from-transfereefrom-transferor
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateTrunk() {
11
const trunk = await client.trunking.v1
12
.trunks("TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.update({ friendlyName: "FriendlyName" });
14
15
console.log(trunk.accountSid);
16
}
17
18
updateTrunk();

Output

1
{
2
"sid": "TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"domain_name": "test.pstn.twilio.com",
5
"disaster_recovery_method": "GET",
6
"disaster_recovery_url": "http://updated-recovery.com",
7
"friendly_name": "FriendlyName",
8
"secure": true,
9
"cnam_lookup_enabled": true,
10
"recording": {
11
"mode": "do-not-record",
12
"trim": "do-not-trim"
13
},
14
"transfer_mode": "disable-all",
15
"transfer_caller_id": "from-transferor",
16
"auth_type": "",
17
"auth_type_set": [],
18
"date_created": "2015-01-02T11:23:45Z",
19
"date_updated": "2015-01-02T11:23:45Z",
20
"url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"links": {
22
"origination_urls": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/OriginationUrls",
23
"credential_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/CredentialLists",
24
"ip_access_control_lists": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IpAccessControlLists",
25
"phone_numbers": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers"
26
}
27
}

DELETE https://trunking.twilio.com/v1/Trunks/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<TK>required

The unique string that we created to identify the Trunk resource to delete.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteTrunk() {
11
await client.trunking.v1
12
.trunks("TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.remove();
14
}
15
16
deleteTrunk();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.