This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Working with Twilio phone numbers
Overview
The following operations are available for working with phone numbers. Click an operation name to see details on how to use it.
For a sample proxy service that illustrates how to work with phone numbers, see Sample configuration.
Operation | Description |
---|---|
addOutgoingPhoneNumber | Adds a new caller ID to your account. |
getOutgoingPhoneNumberList | Returns a list of OutgoingCallerId resource representations, each representing a caller ID number valid for an account. The list includes paging information. |
getOutgoingPhoneNumber | Returns a representation of a specific caller ID number. |
updateOutgoingPhoneNumber | Updates the caller ID, and returns the updated resource if successful. |
removeOutgoingPhoneNumber | Deletes the caller ID from the account. |
getAvailableLocalNumbers | Returns a list of local AvailablePhoneNumber resource representations that match the specified filters, each representing a phone number that is currently available for provisioning within your account. |
getAvailableTollFreeNumbers | Returns a list of AvailableTollFreeNumber resources that match the specified filters, each representing a phone number. |
purchasePhoneNumber | Purchases a new phone number for your account. If a phone number is found for your request, Twilio will add it to your account and bill you for the first month's cost of the phone number. |
getIncomingPhoneNumberList | Returns a list of IncomingPhoneNumber resource representations, each representing a phone number given to your account. The list includes paging information. |
getIncomingPhoneNumber | Returns a IncomingPhoneNumber resource representations, representing a phone number given to your account. |
updateIncomingPhoneNumber | Tries to update the incoming phone number's properties and returns the updated resource representation if successful. |
removeIncomingPhoneNumber | Releases this phone number from your account. Twilio will no longer answer calls to this number, and you will stop being billed the monthly phone number fee. The phone number will eventually be recycled and potentially given to another customer, so use this operation with care. |
Operation details
This section provides further details on the operations related to Phone numbers.
Adding an outgoing phone numberÂ
<twilioRest.addOutgoingPhoneNumber> <phoneNumber>{$ctx:phoneNumber}</phoneNumber> <friendlyName>{$ctx:friendlyName}</friendlyName> <callDelay>{$ctx:callDelay}</callDelay> <extension>{$ctx:extension}</extension> <statusCallback>{$ctx:statusCallback}</statusCallback> <statusCallbackMethod>{$ctx:statusCallbackMethod}</statusCallbackMethod> </twilioRest.addOutgoingPhoneNumber>
To add a new caller ID to your account, use twilioRest.addOutgoingPhoneNumber
 and specify the following properties. After making this request, Twilio returns a validation code and dials the phone number to perform validation. The code returned must be entered via the phone before the caller ID will be added to your account.
Properties
phoneNumber
: The phone number to verify. Should be formatted with a '+' and country code, e.g., +16175551212 (E.164Â format). Twilio will also accept unformatted US numbers, e.g., (415) 555-1212, 415-555-1212.friendlyName
: Optional. A human readable description for the new caller ID with maximum length 64 characters. Defaults to a nicely formatted version of the number.callDelay
: Optional. The number of seconds, between 0 and 60, to delay before initiating the verification call. Defaults to 0.extension
: Optional. Digits to dial after connecting the verification call.statusCallback
: Optional. The URL that Twilio will request when the verification call ends to notify your application whether the verification was successful.statusCallbackMethod
: Optional. The HTTP method, either GET or POST, that should be used to request the status callback URL. Defaults to POST.
Sample request
Following is a sample REST/JSON request that can be handled by the addOutgoingPhoneNumber operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "phoneNumber":"+442033229574", "friendlyName":"My Home Number", "callDelay":"30", "extension":"1234", "statusCallback":"http://demo.twilio.com/docs/statuscallback.xml", "statusCallbackMethod":"post" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/outgoing-caller-ids#list-post
Getting a list of outgoing phone numbersÂ
<twilioRest.getOutgoingPhoneNumberList> <phoneNumber>{$ctx:phoneNumber}</phoneNumber> <friendlyName>{$ctx:friendlyName}</friendlyName> </twilioRest.getOutgoingPhoneNumberList>
To get a list of caller IDs for this account, use twilioRest.getOutgoingPhoneNumberList
 and specify the following properties. The list returns information about each caller ID including the SID, friendly name, and more. The list includes paging information.
Properties
phoneNumber
: Optional. Only shows the caller ID resource with this phone number. Should be formatted with a '+' and country code, e.g., +16175551212 (E.164Â format). Twilio will also accept unformatted US numbers, e.g., (415) 555-1212, 415-555-1212.friendlyName
: Optional. Only shows the caller ID resource with this friendly name.
Sample request
Following is a sample REST/JSON request that can be handled by the getOutgoingPhoneNumberList operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "phoneNumber":"+447891063180" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/outgoing-caller-ids#list-get
Getting a specific outgoing phone numberÂ
<twilioRest.getOutgoingPhoneNumber> <outgoingCallerId>{$ctx:outgoingCallerId}</outgoingCallerId> </twilioRest.getOutgoingPhoneNumber>
To get information about a specific caller ID for this account, use twilioRest.getOutgoingPhoneNumber
 and specify the following properties.
Properties
outgoingCallerId
: The 34-character string that identifies this caller ID record.
Sample request
Following is a sample REST/JSON request that can be handled by the getOutgoingPhoneNumber operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "outgoingCallerId":"PN3021125b69f65961553060dad19131fd" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/outgoing-caller-ids#instance-get
Updating an outgoing phone numberÂ
<twilioRest.updateOutgoingPhoneNumber> <outgoingCallerId>{$ctx:outgoingCallerId}</outgoingCallerId> <friendlyName>{$ctx:friendlyName}</friendlyName> </twilioRest.updateOutgoingPhoneNumber>
To update the friendly name for a caller ID, use twilioRest.updateOutgoingPhoneNumber
 and specify the following properties.
Properties
outgoingCallerId
: The 34-character string that identifies this caller ID record.friendlyName
: The new friendly name for this caller ID.
Sample request
Following is a sample REST/JSON request that can be handled by the updateOutgoingPhoneNumber operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "outgoingCallerId":"PN3021125b69f65961553060dad19131fd", "friendlyName":"Ramesh Number" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/outgoing-caller-ids#instance-post
Removing an outgoing phone numberÂ
<twilioRest.removeOutgoingPhoneNumber> <outgoingCallerId>{$ctx:outgoingCallerId}</outgoingCallerId> </twilioRest.removeOutgoingPhoneNumber>
To remove a caller ID from your account, use twilioRest.removeOutgoingPhoneNumber
 and specify the following properties.
Properties
outgoingCallerId
: The 34-character string that identifies the caller ID record you want to remove from the account.
Sample request
Following is a sample REST/JSON request that can be handled by the removeOutgoingPhoneNumber operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "outgoingCallerId":"PN3021125b69f65961553060dad19131fd" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/outgoing-caller-ids#instance-delete
Getting a list of available local phone numbersÂ
<twilioRest.getAvailableLocalNumbers> <country>{$ctx:country}</country> <areaCode>{$ctx:areaCode}</areaCode> <contains>{$ctx:contains}</contains> <inRegion>{$ctx:inRegion}</inRegion> <inPostalCode>{$ctx:inPostalCode}</inPostalCode> <nearLatLong>{$ctx:nearLatLong}</nearLatLong> <nearNumber>{$ctx:nearNumber}</nearNumber> <inLata>{$ctx:inLata}</inLata> <inRateCenter>{$ctx:inRateCenter}</inRateCenter> <distance>{$ctx:distance}</distance> </twilioRest.getAvailableLocalNumbers>
To get a list of available local phone numbers you can purchase, use twilioRest.getAvailableLocalNumbers
 and specify the following properties.
Properties
country
: The country code (such as US for United States, CA for Canada, and GB for United Kingdom) in which you want to find available toll-free numbers.areaCode
: Optional. Only shows numbers in this area code.contains
: Optional. Only shows numbers that match the specified pattern. Valid characters are * and 0-9a-zA-Z. The * character will match any single digit. For an example, see https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-2.inRegion
: Optional. Only shows numbers in this region (state or province).inPostalCode
: Optional. Only shows numbers in this postal code.nearLatLong
: Optional. Only shows numbers within 25 miles of this latitude/longitude coordinate. To change the search distance from the given coordinate, also specify theÂdistance
 property.nearNumber
: Optional. Only shows numbers within 25 miles of this phone number. To change the search distance from the given number, also specify theÂdistance
 property.inLata
: Optional. Only shows numbers in this Local Access and Transport Area (LATA).ÂinRateCenter
: Optional. Only shows numbers in this rate center.- distance: Optional. Specifies the distance from the coordinate (
nearLatLong
) or number (nearNumber
) to search, up to 500 miles. Defaults to 25.
Sample request
Following is a sample REST/JSON request that can be handled by the getAvailableLocalNumbers operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "country":"US", "areaCode":"415", "contains":"", "inRegion":"CA", "inPostalCode":"94925", "nearLatLong":"", "inLata":"722", "inRateCenter":"CORTEMADRA", "distance":"20" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/available-phone-numbers#local
Getting a list of available toll-free phone numbersÂ
<twilioRest.getAvailableTollFreeNumbers> <country>{$ctx:country}</country> <areaCode>{$ctx:areaCode}</areaCode> <contains>{$ctx:contains}</contains> </twilioRest.getAvailableTollFreeNumbers>
To get a list of available toll-free phone numbers you can purchase, use twilioRest.getAvailableTollFreeNumbers
 and specify the following properties.
Properties
country
: The country code (such as US for United States, CA for Canada, and GB for United Kingdom) in which you want to find available toll-free numbers. For more information on country codes supported by Twilio, see https://www.twilio.com/docs/api/rest/available-phone-numbers#countriesareaCode
: Optional. Only shows numbers in this area code.contains
: Optional. Only shows numbers that match the specified pattern. Valid characters are * and 0-9a-zA-Z. The * character will match any single digit. For an example, see https://www.twilio.com/docs/api/rest/available-phone-numbers#toll-free-get-example-2.
Sample request
Following is a sample REST/JSON request that can be handled by the getAvailableTollFreeNumbers operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "country":"US", "areaCode":"", "contains":"" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/available-phone-numbers#toll-free
Purchasing an incoming phone numberÂ
<twilioRest.purchasePhoneNumber> <phoneNumber>{$ctx:phoneNumber}</phoneNumber> <friendlyName>{$ctx:friendlyName}</friendlyName> <voiceUrl>{$ctx:voiceUrl}</voiceUrl> <voiceMethod>{$ctx:voiceMethod}</voiceMethod> <voiceFallbackUrl>{$ctx:voiceFallbackUrl}</voiceFallbackUrl> <voiceFallbackMethod>{$ctx:voiceFallbackMethod}</voiceFallbackMethod> <statusCallback>{$ctx:statusCallback}</statusCallback> <statusCallbackMethod>{$ctx:statusCallbackMethod}</statusCallbackMethod> <voiceCallerIdLookup>{$ctx:voiceCallerIdLookup}</voiceCallerIdLookup> <smsUrl>{$ctx:smsUrl}</smsUrl> <smsMethod>{$ctx:smsMethod}</smsMethod> <smsFallbackUrl>{$ctx:smsFallbackUrl}</smsFallbackUrl> <smsFallbackMethod>{$ctx:smsFallbackMethod}</smsFallbackMethod> </twilioRest.purchasePhoneNumber>
To purchase an incoming phone number, use twilioRest.purchasePhoneNumber
 and specify the following properties.
Properties
phoneNumber
 orÂareaCode
: Specify the exact phone number you want to purchase, or specify an area code to search for and purchase a phone number in that area code. Only specify one of these properties. If specifying the phone number, it should be formatted starting with a '+' followed by the country code and the number in E.164 format, e.g., '+15105555555'. If specifying the area code, any three-digit, US or Canada area code is valid. Twilio will provision a random phone number within this area code for you.friendlyName
: The friendly name for this phone number.voiceUrl
: The URL that Twilio should request when somebody dials this phone number.voiceMethod
: Optional. The HTTP method, either GET or POST, that should be used to request the voice URL. Defaults to POST.voiceFallbackUrl
: Optional. A URL that Twilio will request if an error occurs when requests are made to the voice URL.voiceFallbackMethod
: Optional. The HTTP method, either GET or POST, that should be used to request the voice fallback URL. Defaults to POST.statusCallback
: Optional. The URL that Twilio will request to pass status parameters (such as call ended) to your application.statusCallbackMethod
: Optional. The HTTP method, either GET or POST, that should be used to request the status callback URL. Defaults to POST.voiceCallerIdLookup
: Optional. If true, performs a lookup of the caller's name from the CNAM database and posts it to your app. Defaults to false.smsUrl
: The URL that Twilio should request when somebody sends an SMS to this phone number.smsMethod
: Optional. The HTTP method, either GET or POST, that should be used to request the SMS URL. Defaults to POST.smsFallbackUrl
: Optional. The URL that Twilio will request if an error occurs when requests are made to the SMS URL.smsFallbackMethod
: Optional. The HTTP method, either GET or POST, that should be used to request the SMS fallback URL. Defaults to POST.apiVersion
: Optional. Already specify in twilioRest.initÂ
Sample request
Following is a sample REST/JSON request that can be handled by the purchasePhoneNumber operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "phoneNumber":"+441287244059", "friendlyName":"New phone number", "voiceUrl":"http://demo.twilio.com/docs/voice.xml", "voiceMethod":"POST", "voiceFallbackUrl":"http://demo.twilio.com/docs/voicefallback.xml", "voiceFallbackMethod":"POST", "statusCallback":"http://demo.twilio.com/docs/statuscallback.xml", "statusCallbackMethod":"GET", "voiceCallerIdLookup":"false", "smsUrl":"", "smsMethod":"", "smsFallbackUrl":"", "smsFallbackMethod":"" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/incoming-phone-numbers#list-post
Getting a list of incoming phone numbersÂ
<twilioRest.getIncomingPhoneNumberList configKey="MyTwilioConfig"> <phoneNumber>{$ctx:phoneNumber}</phoneNumber> <friendlyName>{$ctx:friendlyName}</friendlyName> </twilioRest.getIncomingPhoneNumberList>
To get a list of incoming phone numbers for this account, use twilioRest.getIncomingPhoneNumberList
 and specify the following properties. The list returns information about each phone number including the SID, friendly name, and more. The list includes paging information.
Properties
phoneNumber
: Optional. Only shows the incoming phone number resources that match this pattern. You can specify partial numbers and useÂ*
 as a wildcard for any digit.friendlyName
: Optional. Only shows the incoming phone number resources whose friendly names exactly match this name.
Sample request
Following is a sample REST/JSON request that can be handled by the getIncomingPhoneNumberList operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "phoneNumber":"+442033229574" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/incoming-phone-numbers#list
Getting a specific incoming phone numberÂ
<twilioRest.getIncomingPhoneNumber> <incomingCallerId>{$ctx:incomingCallerId}</incomingCallerId> </twilioRest.getIncomingPhoneNumber>
To get information about a specific caller ID for this account, use twilioRest.getIncomingPhoneNumber
 and specify the following properties.
Properties
incomingCallerId
: The 34-character string that identifies this incoming phone number record.
Sample request
Following is a sample REST/JSON request that can be handled by the getIncomingPhoneNumber operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "incomingCallerId":"PNa82d94f7329c9a0bbba7a829a490a0e5" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/incoming-phone-numbers#instance-get
Updating an incoming phone numberÂ
<twilioRest.updateIncomingPhoneNumber> <incomingCallerId>{$ctx:incomingCallerId}</incomingCallerId> <friendlyName>{$ctx:friendlyName}</friendlyName> <voiceUrl>{$ctx:voiceUrl}</voiceUrl> <voiceMethod>{$ctx:voiceMethod}</voiceMethod> <voiceFallbackUrl>{$ctx:voiceFallbackUrl}</voiceFallbackUrl> <voiceFallbackMethod>{$ctx:voiceFallbackMethod}</voiceFallbackMethod> <statusCallback>{$ctx:statusCallback}</statusCallback> <statusCallbackMethod>{$ctx:statusCallbackMethod}</statusCallbackMethod> <voiceCallerIdLookup>{$ctx:voiceCallerIdLookup}</voiceCallerIdLookup> <smsUrl>{$ctx:smsUrl}</smsUrl> <smsMethod>{$ctx:smsMethod}</smsMethod> <smsFallbackUrl>{$ctx:smsFallbackUrl}</smsFallbackUrl> <smsFallbackMethod>{$ctx:smsFallbackMethod}</smsFallbackMethod> </twilioRest.updateIncomingPhoneNumber>
To update the properties of an incoming phone number, use twilioRest.updateIncomingPhoneNumber
, specify the phone number's SID, and then specify one or more of the properties you set when purchasing the phone number.
Sample request
Following is a sample REST/JSON request that can be handled by the updateIncomingPhoneNumber operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "incomingCallerId":"PNa82d94f7329c9a0bbba7a829a490a0e5", "friendlyName":"update Incoming Phone number", "phoneNumber":"", "voiceUrl":"http://demo.twilio.com/docs/voice.xml", "voiceMethod":"POST", "voiceFallbackUrl":"http://demo.twilio.com/docs/voicefallback.xml", "voiceFallbackMethod":"POST", "statusCallback":"http://demo.twilio.com/docs/statuscallback.xml", "statusCallbackMethod":"", "voiceCallerIdLookup":"", "smsUrl":"", "smsMethod":"POST", "smsFallbackUrl":"http://demo.twilio.com/docs/smsfallback.xml", "smsFallbackUrlMethod":"" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/incoming-phone-numbers#instance-post
Removing an incoming phone numberÂ
<twilioRest.removeIncomingPhoneNumber> <incomingCallerId>{$ctx:incomingCallerId}</incomingCallerId> </twilioRest.removeIncomingPhoneNumber>
To remove an incoming phone number from your account, use twilioRest.removeIncomingPhoneNumber
 and specify the following properties.
Properties
incomingCallerId
: The 34-character string that identifies the incoming phone number record you want to remove from the account.
Sample request
Following is a sample REST/JSON request that can be handled by the removeIncomingPhoneNumber
 operation.
{ "accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6", "authToken":"cdd1fdb143d482a05e4f1f6fdb195395", "apiUrl":"https://api.twilio.com", "apiVersion":"2010-04-01", "incomingCallerId":"PNa82d94f7329c9a0bbba7a829a490a0e5" }
Related Twilio documentation
https://www.twilio.com/docs/api/rest/incoming-phone-numbers#instance-delete
Sample configuration
Following is a sample proxy service that illustrates how to connect to TwilioRest with the init
 operation and use the updateOutgoingPhoneNumber operation. The sample request for this proxy can be found in updateOutgoingPhoneNumber sample request. You can use this sample as a template for using other operations in this category.
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="twilioRest" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence onError="faultHandlerSeq"> <property name="accountSid" expression="//accountSid/text()"/> <property name="authToken" expression="//authToken/text()"/> <property name="apiUrl" expression="//apiUrl/text()"/> <property name="apiVersion" expression="//apiVersion/text()"/> <property name="outgoingCallerId" expression="//outgoingCallerId/text()"/> <property name="friendlyName" expression="//friendlyName/text()"/> <twilioRest.init> <accountSid>{$ctx:accountSid}</accountSid> <authToken>{$ctx:authToken}</authToken> <apiUrl>{$ctx:apiUrl}</apiUrl> <apiVersion>{$ctx:apiVersion}</apiVersion> </twilioRest.init> <twilioRest.updateOutgoingPhoneNumber> <outgoingCallerId>{$ctx:outgoingCallerId}</outgoingCallerId> <friendlyName>{$ctx:friendlyName}</friendlyName> </twilioRest.updateOutgoingPhoneNumber> <respond/> </inSequence> <outSequence> <log/> <send/> </outSequence> </target> <description/> </proxy>
Â
Â