Twilio: Purchase a phone-number for the account
Twilio incomingPhoneNumber.createIncomingPhoneNumber: arguments, response, policy and SDK examples.
← Incoming phone number operations · Get started
Operation twilio.createincomingphonenumber
Provider route: POST /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json. Alter supplies the connection’s credentials and routing.
Call through Alter
Section titled “Call through Alter”Install @alter-ai/sdk @alter-ai/twilio with npm, or alter-sdk-twilio with pip. Supply your connected customer’s grant ID and the arguments described below.
import { App } from "@alter-ai/sdk";import { TwilioIntegration } from "@alter-ai/twilio";
async function execute(input: Parameters<TwilioIntegration["incomingPhoneNumber"]["createIncomingPhoneNumber"]>[0]) { const app = new App({ apiKey: process.env.ALTER_API_KEY! }); try { const provider = new TwilioIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! }); const call = await provider.incomingPhoneNumber.createIncomingPhoneNumber(input); const result = await call.wait(); return result.bodyJson(); } finally { await app.close(); }}import osfrom alter_sdk import Appfrom alter_sdk_twilio import TwilioIntegration
async def execute(arguments): async with App(api_key=os.environ["ALTER_API_KEY"]) as app: provider = TwilioIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]}) call = await provider.incoming_phone_number.create_incoming_phone_number(arguments) result = await call.wait() return result.body_json()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
path | object | Required within parent | Additional keys: not allowed |
path.AccountSid | string | Required within parent | Maximum length: 34 Minimum length: 34 Pattern: ^AC[0-9a-fA-F]{32}$ |
body | object | Optional | |
body.AddressSid | string | Optional | The SID of the Address resource we should associate with the new phone number. Some regions require addresses to meet local regulations. Maximum length: 34 Minimum length: 34 Pattern: ^AD[0-9a-fA-F]{32}$ |
body.ApiVersion | string | Optional | The API version to use for incoming calls made to the new phone number. The default is `2010-04-01`. |
body.AreaCode | string | Optional | 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). |
body.BundleSid | string | Optional | The SID of the Bundle resource that you associate with the phone number. Some regions require a Bundle to meet local Regulations. Maximum length: 34 Minimum length: 34 Pattern: ^BU[0-9a-fA-F]{32}$ |
body.EmergencyAddressSid | string | Optional | The SID of the emergency address configuration to use for emergency calling from the new phone number. Maximum length: 34 Minimum length: 34 Pattern: ^AD[0-9a-fA-F]{32}$ |
body.EmergencyStatus | string | Optional | The parameter displays if emergency calling is enabled for this number. Active numbers may place emergency calls by dialing valid emergency numbers for the country. One of: Active, Inactive |
body.FriendlyName | string | Optional | 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. |
body.IdentitySid | string | Optional | The SID of the Identity resource that we should associate with the new phone number. Some regions require an identity to meet local regulations. Maximum length: 34 Minimum length: 34 Pattern: ^RI[0-9a-fA-F]{32}$ |
body.PhoneNumber | string | Optional | The phone number to purchase specified in [E.164](https://www.twilio.com/docs/glossary/what-e164) format. E.164 phone numbers consist of a + followed by the country code and subscriber number without punctuation characters. For example, +14155551234. Format: phone-number |
body.SmsApplicationSid | string | Optional | 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. Maximum length: 34 Minimum length: 34 Pattern: ^AP[0-9a-fA-F]{32}$ |
body.SmsFallbackMethod | string | Optional | The HTTP method that we should use to call `sms_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`. One of: GET, POST Format: http-method |
body.SmsFallbackUrl | string | Optional | The URL that we should call when an error occurs while requesting or executing the TwiML defined by `sms_url`. Format: uri |
body.SmsMethod | string | Optional | The HTTP method that we should use to call `sms_url`. Can be: `GET` or `POST` and defaults to `POST`. One of: GET, POST Format: http-method |
body.SmsUrl | string | Optional | The URL we should call when the new phone number receives an incoming SMS message. Format: uri |
body.StatusCallback | string | Optional | The URL we should call using the `status_callback_method` to send status information to your application. Format: uri |
body.StatusCallbackMethod | string | Optional | The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST` and defaults to `POST`. One of: GET, POST Format: http-method |
body.TrunkSid | string | Optional | 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. Maximum length: 34 Minimum length: 34 Pattern: ^TK[0-9a-fA-F]{32}$ |
body.VoiceApplicationSid | string | Optional | 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. Maximum length: 34 Minimum length: 34 Pattern: ^AP[0-9a-fA-F]{32}$ |
body.VoiceCallerIdLookup | boolean | Optional | 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`. |
body.VoiceFallbackMethod | string | Optional | The HTTP method that we should use to call `voice_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`. One of: GET, POST Format: http-method |
body.VoiceFallbackUrl | string | Optional | The URL that we should call when an error occurs retrieving or executing the TwiML requested by `url`. Format: uri |
body.VoiceMethod | string | Optional | The HTTP method that we should use to call `voice_url`. Can be: `GET` or `POST` and defaults to `POST`. One of: GET, POST Format: http-method |
body.VoiceReceiveMode | string | Optional | One of: voice, fax |
body.VoiceUrl | string | Optional | 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. Format: uri |
Response
Section titled “Response”Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | Model | Root | Expand Purchase a phone-number for the account — response body |
Referenced models: Purchase a phone-number for the account — response body
Schemas
Section titled “Schemas”1 more schema is linked from the tables above, on the schema pages.
Policy, approvals and errors
Section titled “Policy, approvals and errors”SDK function policy ID: twilio.createincomingphonenumber. Catalog operation: CreateIncomingPhoneNumber. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.
Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.