Make an outbound phone call using REST API in a non-US Twilio Region
To make an outbound Call using the Twilio REST API in a Region other than the default, United States (US1) Region, send a POST request to the Call resource at the target Region's fully qualified domain name (FQDN). This guide uses the Ireland (IE1) Region as the example.
Before you begin, review the guides on making outbound calls and Twilio Regions.
Before proceeding, make sure that you have the following items handy:
- Your Twilio Account SID
- A Voice-capable Twilio phone number
See the guide on how to search for and buy a Twilio phone number for help finding and purchasing a Twilio phone number.
Next, you need a Twilio API Key that's valid in the target Region.
Twilio API Keys are a Region-specific resource. To interact with the API in the IE1 Region, you need to use an API Key which exists in that Region (rather than an API Key you created in the default US1 Region, for example). Refer to the Twilio Regions overview for more information about the Region isolation model.
Follow these steps to create an API Key for the IE1 Region using the Twilio Console:
- Log in to the Twilio Console.
- Navigate to Develop > API Keys & creds > API Keys & auth tokens.
- Use the Region selector dropdown to switch between Regions and select the IE1 Region.
- Click Create API key.
- Enter a name for the API key and select the "Standard" key type.
- Make note of the API Key SID and secret for use in the next step.
- Click Finish.
The Twilio REST API operates on a per-Region basis. When making requests to the API, it's up to you to select which Region handles the request. Whichever Region you choose is the Region that processes and stores data related to the request.
If you don't specify a target Region for a request, the request is handled in the default US1 Region.
To specify a target Region for a request, you will include the name of the target Region in the request's hostname, also known as the fully qualified domain name (FQDN).
The FQDN format follows a convention that encodes three pieces of information in the hostname:
- The Twilio Product
- The target Edge Location
- The target Region
The format of an FQDN is:
{product}.{edge-location}.{region}.twilio.com
Some example FQDNs targeting API products in different Regions (through various Edge Locations) include:
| FQDN | Target region |
|---|---|
| studio.sydney.au1.twilio.com | Australia (AU1) Region |
| events.ashburn.us1.twilio.com | United States (US1) Region |
| messaging.dublin.ie1.twilio.com | Ireland (IE1) Region |
Warning
Legacy FQDNs which do not include the Edge Location and Region (for example, video.twilio.com) are implicitly routed to the US1 Region through the ashburn Edge Location.
In this example, you make a POST request to the Call resource endpoint to create a Call. This endpoint is part of Twilio's core API product. You select the dublin Edge Location and the IE1 processing Region.
The FQDN you need to use is:
api.dublin.ie1.twilio.com
Info
You can use the Twilio server-side SDKs for making API requests to a target Region. SDKs accept an edge and region parameter, and automatically construct the appropriate FQDN for API requests.
If you use a MacOS or Linux operating system, you can follow these instructions to issue the request using the cURL command line utility. Otherwise, please continue to read along, since this section contains important information.
First, set some environment variables containing data that the curl command references later. This keeps sensitive data out of shell commands and makes the curl command copy-pasteable without adjusting placeholder values.
Create a new file named .env, and add the following content, using your own Account SID, API Key SID, and API Key secret:
1export ACCOUNT_SID=<your_account_sid_here>2export API_KEY_SID=<your_api_key_sid_here>3export API_KEY_SECRET=<your_api_key_secret_here>
Next, add E.164 formatted phone number values for the To and From number of the phone call that you want to make. Be sure to use a From number that is either a Twilio phone number you own, or a verified phone number associated with your Twilio account.
1export TO_NUMBER=<your_to_number_here>2export FROM_NUMBER=<your_from_number_here>
Save the file, and run the source command in a terminal to set the file's values as variables in your shell session:
source .env
Confirm that the variables are set by echoing one of them:
echo $TO_NUMBER
The shell should print the value of the To number that you set in the .env file.
Run the following command to issue the API request.
1curl -X POST \2-u $API_KEY_SID:$API_KEY_SECRET \3https://api.dublin.ie1.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/Calls.json \4--data-urlencode "To=$TO_NUMBER" \5--data-urlencode "From=$FROM_NUMBER" \6--data-urlencode "Twiml=<Response><Say>Ahoy from Ireland</Say></Response>"
The command should print a JSON representation of the new Call, and the destination phone should now be ringing.
You've successfully created a Call using a non-US1 Twilio Region.
Keep in mind that this Call will only exist in the Region where it was created — IE1 in this case. In order to view the Call log in the Twilio Console, for example, you'll need to access the IE1-specific Call Logs page. Refer to the Twilio Regions introduction for a refresher on Twilio's Region isolation model.
Production applications typically use an HTTP client appropriate for the application's programming language rather than cURL. A common choice is one of Twilio's language-specific server-side SDKs.
These libraries help you issue requests against a target Region by setting a region attribute on a client instance.
For example, using one of the SDKs, a request equivalent to the one sent using the curl command in the previous step could be sent using the following language-specific code:
1const accountSid = process.env.ACCOUNT_SID;2const apiKeySid = process.env.API_KEY_SID;3const apiKeySecret = process.env.API_KEY_SECRET;45const toNumber = process.env.TO_NUMBER;6const fromNumber = process.env.FROM_NUMBER;78const client = require('twilio')(apiKeySid, apiKeySecret, {9accountSid: accountSid,10edge: 'dublin',11region: 'ie1',12});1314client.calls.create({15twiml: '<Response><Say>Ahoy from Ireland</Say></Response>',16to: toNumber,17from: fromNumber,18});
Explore these resources to learn more about building with Twilio Regions: