Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

REST API: Incoming Phone Numbers

An IncomingPhoneNumber instance resource represents a Twilio phone number purchased from Twilio, ported or hosted to Twilio.

The IncomingPhoneNumbers list resource represents an account's Twilio phone numbers. You can POST to the list resource to provision a new Twilio number. To find a new number to provision use the subresources of the AvailablePhoneNumbers resource.

You can transfer phone numbers between two Twilio accounts if you're using subaccounts. For details, see Exchanging Numbers Between Subaccounts.

Provisioning a phone number is a two-step process. First, you must find an available phone number to provision using the subresources of the AvailablePhoneNumbers resource. Second, you must POST to the IncomingPhoneNumbers list resource, documented below.

IncomingPhoneNumber Properties

Each instance of an IncomingPhoneNumber resource has the following properties:

Names in PHP format
accountSid
sid<AC> Not PII

The SID of the Account that created this IncomingPhoneNumber resource.

addressSid
sid<AD> Not PII

The SID of the Address resource associated with the phone number.

addressRequirements
enum:address_requirement Not PII

Whether the phone number requires an Address registered with Twilio. Can be: none, any, local, or foreign.

apiVersion
string Not PII

The API version used to start a new TwiML session.

beta
boolean Not PII

Whether the phone number is new to the Twilio platform. Can be: true or false.

capabilities
phone_number_capabilities Not PII

The set of Boolean properties that indicate whether a phone number can receive calls or messages. Capabilities are Voice, SMS, and MMS and each capability can be: true or false.

dateCreated
date_time<rfc2822> Not PII

The date and time in GMT that the resource was created specified in RFC 2822 format.

dateUpdated
date_time<rfc2822> Not PII

The date and time in GMT that the resource was last updated specified in RFC 2822 format.

friendlyName

The string that you assigned to describe the resource.

identitySid
sid<RI> Not PII

The SID of the Identity resource that we associate with the phone number. Some regions require an Identity to meet local regulations.

phoneNumber
phone_number Not PII

The phone number in E.164 format, which consists of a + followed by the country code and subscriber number.

origin
string Not PII

The phone number's origin. twilio identifies Twilio-owned phone numbers and hosted identifies hosted phone numbers.

sid
sid<PN> Not PII

The unique string that that we created to identify this IncomingPhoneNumber resource.

smsApplicationSid
sid<AP> Not PII

The SID of the application that handles SMS messages sent to the phone number. If an sms_application_sid is present, we ignore all sms_*_url values and use those of the application.

smsFallbackMethod
http_method Not PII

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

smsFallbackUrl
url Not PII

The URL that we call when an error occurs while retrieving or executing the TwiML from sms_url.

smsMethod
http_method Not PII

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

smsUrl
url Not PII

The URL we call when the phone number receives an incoming SMS message.

statusCallback
url Not PII

The URL we call using the status_callback_method to send status information to your application.

statusCallbackMethod
http_method Not PII

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

trunkSid
sid<TR> Not PII

The SID of the Trunk that handles calls to the phone number. If a trunk_sid is present, we ignore all of the voice urls and voice applications and use those set on the Trunk. Setting a trunk_sid will automatically delete your voice_application_sid and vice versa.

uri
uri Not PII

The URI of the resource, relative to https://api.twilio.com.

voiceApplicationSid
sid<AP> Not PII

The SID of the application that handles calls to the phone number. If a voice_application_sid is present, we ignore all of the voice urls and use those set on the application. Setting a voice_application_sid will automatically delete your trunk_sid and vice versa.

voiceCallerIdLookup
boolean Not PII

Whether we look up the caller's caller-ID name from the CNAM database ($0.01 per look up). Can be: true or false.

voiceFallbackMethod
http_method Not PII

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

voiceFallbackUrl
url Not PII

The URL that we call when an error occurs retrieving or executing the TwiML requested by url.

voiceMethod
http_method Not PII

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

voiceUrl
url Not PII

The URL we call when the phone number receives a call. The voice_url will not be used if a voice_application_sid or a trunk_sid is set.

emergencyStatus
enum:emergency_status Not PII

The configuration status parameter that determines whether the phone number is enabled for emergency calling.

emergencyAddressSid
sid<AD> Not PII

The SID of the emergency address configuration that we use for emergency calling from this phone number.

Address Requirements Values

The following are the possible values for the address_requirements property.

Status Description
none An Address is not required for this phone number.
any Your account must have an Address, but it can be anywhere in the world.
local Your account must have an Address within the phone number's country.
foreign Your account must have an Address outside the phone number's country.
POST
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers

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. If Twilio cannot find a phone number to match your request, you will receive an HTTP 400 with Twilio error code 21452.

If the number you are trying to purchase has address requirements, the system will look for an address on your account that satisfies the requirement. If you have multiple addresses, you can specify which address to associate with the number by passing the optional AddressSid parameter.

If the number you are trying to purchase requires an identity document on file and you don’t have a verified identity document associated with your account, you will receive an HTTP 400 with Twilio error code 21650. See this support article for more details.

To find an available phone number to POST, use the subresources of the AvailablePhoneNumbers list resource.

Please note: You cannot request numbers via the API while you are using a Free Trial account. You must upgrade your account to purchase a Twilio phone number programmatically.

Parameters

Your request may include the following parameters:

Names in PHP format
accountSid
Required
post sid<AC> Not PII

The SID of the Account that will create the resource.

phoneNumber
Required if areaCode is not passed
post phone_number Not PII

The phone number to purchase specified in E.164 format. E.164 phone numbers consist of a + followed by the country code and subscriber number without punctuation characters. For example, +14155551234.

areaCode
Required if phoneNumber is not passed
post string Not PII

The desired area code for your new incoming phone number. Can be any three-digit, US or Canada area code. We will provision an available phone number within this area code for you. You must provide an area_code or a phone_number. (US and Canada only).

apiVersion
Optional
post string Not PII

The API version to use for incoming calls made to the new phone number. The default is 2010-04-01.

friendlyName
Optional
post string PII MTL: 30 DAYS

A descriptive string that you created to describe the new phone number. It can be up to 64 characters long. By default, this is a formatted version of the new phone number.

smsApplicationSid
Optional
post sid<AP> Not PII

The SID of the application that should handle SMS messages sent to the new phone number. If an sms_application_sid is present, we ignore all of the sms_*_url urls and use those set on the application.

smsFallbackMethod
Optional
post http_method Not PII

The HTTP method that we should use to call sms_fallback_url. Can be: GET or POST and defaults to POST.

smsFallbackUrl
Optional
post url Not PII

The URL that we should call when an error occurs while requesting or executing the TwiML defined by sms_url.

smsMethod
Optional
post http_method Not PII

The HTTP method that we should use to call sms_url. Can be: GET or POST and defaults to POST.

smsUrl
Optional
post url Not PII

The URL we should call when the new phone number receives an incoming SMS message.

statusCallback
Optional
post url Not PII

The URL we should call using the status_callback_method to send status information to your application.

statusCallbackMethod
Optional
post http_method Not PII

The HTTP method we should use to call status_callback. Can be: GET or POST and defaults to POST.

voiceApplicationSid
Optional
post sid<AP> Not PII

The SID of the application we should use to handle calls to the new phone number. If a voice_application_sid is present, we ignore all of the voice urls and use only those set on the application. Setting a voice_application_sid will automatically delete your trunk_sid and vice versa.

voiceCallerIdLookup
Optional
post boolean Not PII

Whether to lookup the caller's name from the CNAM database and post it to your app. Can be: true or false and defaults to false.

voiceFallbackMethod
Optional
post http_method Not PII

The HTTP method that we should use to call voice_fallback_url. Can be: GET or POST and defaults to POST.

voiceFallbackUrl
Optional
post url Not PII

The URL that we should call when an error occurs retrieving or executing the TwiML requested by url.

voiceMethod
Optional
post http_method Not PII

The HTTP method that we should use to call voice_url. Can be: GET or POST and defaults to POST.

voiceUrl
Optional
post url Not PII

The URL that we should call to answer a call to the new phone number. The voice_url will not be called if a voice_application_sid or a trunk_sid is set.

emergencyStatus
Optional
post enum:emergency_status Not PII

The configuration status parameter that determines whether the new phone number is enabled for emergency calling.

emergencyAddressSid
Optional
post sid<AD> Not PII

The SID of the emergency address configuration to use for emergency calling from the new phone number.

trunkSid
Optional
post sid<TR> Not PII

The SID of the Trunk we should use to handle calls to the new phone number. If a trunk_sid is present, we ignore all of the voice urls and voice applications and use only those set on the Trunk. Setting a trunk_sid will automatically delete your voice_application_sid and vice versa.

identitySid
Optional
post sid<RI> Not PII

The SID of the Identity resource that we should associate with the new phone number. Some regions require an identity to meet local regulations.

addressSid
Optional
post sid<AD> Not PII

The SID of the Address resource we should associate with the new phone number. Some regions require addresses to meet local regulations.

voiceReceiveMode
Optional
post enum:voice_receive_mode Not PII

The configuration parameter for the new phone number to receive incoming voice calls or faxes. Can be: fax or voice and defaults to voice.

If successful, Twilio responds with a representation of the new phone number that was assigned to your account.

Example
        
        
        
        
        GET
        https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{IncomingPhoneNumberSid}
              
              
              
              
              GET
              https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers

              Returns a list of IncomingPhoneNumber resource representations, each representing a phone number given to your account. The list includes paging information.

              List Filters

              The following query string parameters allow you to limit the list returned. Note, parameters are case-sensitive:

              Names in PHP format
              accountSid
              Required
              get sid<AC> Not PII

              The SID of the Account that created the IncomingPhoneNumber resources to read.

              beta
              Optional
              get boolean Not PII

              Whether to include phone numbers new to the Twilio platform. Can be: true or false and the default is true.

              friendlyName
              Optional
              get string PII MTL: 30 DAYS

              A string that identifies the IncomingPhoneNumber resources to read.

              phoneNumber
              Optional
              get phone_number Not PII

              The phone numbers of the IncomingPhoneNumber resources to read. You can specify partial numbers and use '*' as a wildcard for any digit.

              origin
              Optional
              get string Not PII

              Whether to include phone numbers based on their origin. Can be: twilio or hosted. By default, phone numbers of all origin are included.

                    
                    
                    
                    
                    Example 2

                    Return the set of phone numbers that match exactly (415) 867-5309.

                          
                          
                          
                          
                          Example 3

                          Return the set of all phone numbers containing the digits 867.

                                
                                
                                
                                
                                POST
                                https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{IncomingPhoneNumberSid}

                                Tries to update the incoming phone number's properties, and returns the updated resource representation if successful. The returned response is identical to that returned above when making a GET request.

                                Parameters

                                You may specify one or more of the following parameters to update this phone number's respective properties:

                                Names in PHP format
                                accountSid
                                Optional
                                post sid<AC> Not PII

                                The SID of the Account that created the IncomingPhoneNumber resource to update. For more information, see Exchanging Numbers Between Subaccounts.

                                sid
                                Required
                                post sid<PN> Not PII

                                The Twilio-provided string that uniquely identifies the IncomingPhoneNumber resource to update.

                                apiVersion
                                Optional
                                post string Not PII

                                The API version to use for incoming calls made to the phone number. The default is 2010-04-01.

                                friendlyName
                                Optional
                                post string PII MTL: 30 DAYS

                                A descriptive string that you created to describe this phone number. It can be up to 64 characters long. By default, this is a formatted version of the phone number.

                                smsApplicationSid
                                Optional
                                post sid<AP> Not PII

                                The SID of the application that should handle SMS messages sent to the number. If an sms_application_sid is present, we ignore all of the sms_*_url urls and use those set on the application.

                                smsFallbackMethod
                                Optional
                                post http_method Not PII

                                The HTTP method that we should use to call sms_fallback_url. Can be: GET or POST and defaults to POST.

                                smsFallbackUrl
                                Optional
                                post url Not PII

                                The URL that we should call when an error occurs while requesting or executing the TwiML defined by sms_url.

                                smsMethod
                                Optional
                                post http_method Not PII

                                The HTTP method that we should use to call sms_url. Can be: GET or POST and defaults to POST.

                                smsUrl
                                Optional
                                post url Not PII

                                The URL we should call when the phone number receives an incoming SMS message.

                                statusCallback
                                Optional
                                post url Not PII

                                The URL we should call using the status_callback_method to send status information to your application.

                                statusCallbackMethod
                                Optional
                                post http_method Not PII

                                The HTTP method we should use to call status_callback. Can be: GET or POST and defaults to POST.

                                voiceApplicationSid
                                Optional
                                post sid<AP> Not PII

                                The SID of the application we should use to handle phone calls to the phone number. If a voice_application_sid is present, we ignore all of the voice urls and use only those set on the application. Setting a voice_application_sid will automatically delete your trunk_sid and vice versa.

                                voiceCallerIdLookup
                                Optional
                                post boolean Not PII

                                Whether to lookup the caller's name from the CNAM database and post it to your app. Can be: true or false and defaults to false.

                                voiceFallbackMethod
                                Optional
                                post http_method Not PII

                                The HTTP method that we should use to call voice_fallback_url. Can be: GET or POST and defaults to POST.

                                voiceFallbackUrl
                                Optional
                                post url Not PII

                                The URL that we should call when an error occurs retrieving or executing the TwiML requested by url.

                                voiceMethod
                                Optional
                                post http_method Not PII

                                The HTTP method that we should use to call voice_url. Can be: GET or POST and defaults to POST.

                                voiceUrl
                                Optional
                                post url Not PII

                                The URL that we should call to answer a call to the phone number. The voice_url will not be called if a voice_application_sid or a trunk_sid is set.

                                emergencyStatus
                                Optional
                                post enum:emergency_status Not PII

                                The configuration status parameter that determines whether the phone number is enabled for emergency calling.

                                emergencyAddressSid
                                Optional
                                post sid<AD> Not PII

                                The SID of the emergency address configuration to use for emergency calling from this phone number.

                                trunkSid
                                Optional
                                post sid<TR> Not PII

                                The SID of the Trunk we should use to handle phone calls to the phone number. If a trunk_sid is present, we ignore all of the voice urls and voice applications and use only those set on the Trunk. Setting a trunk_sid will automatically delete your voice_application_sid and vice versa.

                                voiceReceiveMode
                                Optional
                                post enum:voice_receive_mode Not PII

                                The configuration parameter for the phone number to receive incoming voice calls or faxes. Can be: fax or voice and defaults to voice.

                                identitySid
                                Optional
                                post sid<RI> Not PII

                                The SID of the Identity resource that we should associate with the phone number. Some regions require an identity to meet local regulations.

                                addressSid
                                Optional
                                post sid<AD> Not PII

                                The SID of the Address resource we should associate with the phone number. Some regions require addresses to meet local regulations.

                                Example 1

                                Set the VoiceUrl and SmsUrl on a phone number

                                      
                                      
                                      
                                      
                                      DELETE
                                      https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{IncomingPhoneNumberSid}

                                      Release 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 with care. If you make a mistake, contact us. We may be able to give you the number back.

                                      If successful, returns an HTTP 204 response with no body.

                                      Example 1

                                      Release a phone number from your account.

                                            
                                            
                                            
                                            
                                            Rate this page:

                                            Need some help?

                                            We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.