You can use Twilio Regions to select the location where Twilio carries out the processing and storage of data related to your Twilio usage. Controlling which Region Twilio uses can enable you to meet data residency requirements and reduce API request latency.
This guide will show you how to send an SMS message using the Twilio REST API in a Region other than the United States (US1) Region. The examples in this guide will use the Ireland (IE1) Region.
Please ensure that you understand the basic concepts explained in our Twilio Regions guide before reading this walkthrough.
Make sure you have the following items handy:
Before you get started, ensure that your Twilio phone number has a configuration record in the IE1 Region. Follow the instructions in this guide to set up Multi-Region navigation in the Console, and then follow the steps to create a configuration for your phone number in the IE1 Region.
You will also need a Twilio API Key in the target Twilio Region. To create an API key in the IE1 Region using the Twilio Console, follow these steps:
Make a note of the API Key's SID and Secret . You will need this information during the next step.
Every API request you send to Twilio is processed in a Twilio Region.
To control which Twilio Region is used for handling a given API request, you must specify a target Region and Edge Location in the hostname of the request. Read more about selecting the target Region for your Twilio API requests in our guide to using the API in non-US1 Regions.
If you don't explicitly specify a target Region for your request, the request will be handled in the US1 Region.
In this example you will use the following hostname to make an API request against the IE1 Region via the dublin
Edge Location.
api.dublin.ie1.twilio.com
If you're using any of Twilio's server-side helper libraries to make API requests, you don't need to worry about constructing the hostname yourself. Instead, you can pass edge
and region
parameters as arguments to the client constructor, and then the client will automatically construct the hostname for all requests accordingly. See step 3, below, for an example.
For a complete list of available Region and Edge options, refer to the Region and Edge Location availability pages.
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 that will be referenced from the curl
command later. This practice prevents you from needing to include sensitive data directly in shell commands.
Create a new file named .env
, and add the following content. Be sure to use your own Account SID, along with the API Key SID and secret for an API Key that you created in IE1.
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>45export TO_NUMBER=<your_to_number_here>6export FROM_NUMBER=<your_from_number_here>
Save the file, and run this command in a terminal to source the file and set the environment variables in your shell session:
source .env
Finally, run this curl command to make an HTTP POST
request to your account's Message resource endpoint.
1curl -X POST \2-u $API_KEY_SID:$API_KEY_SECRET \3https://api.dublin.ie1.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/Messages.json \4--data-urlencode "Body=Ahoy from Ireland!" \5--data-urlencode "To=$TO_NUMBER" \6--data-urlencode "From=$FROM_NUMBER"
The command should print the response, which includes a JSON representation of the Message you just created. The destination phone should receive the SMS momentarily.
To confirm that the Message data was indeed processed and stored in the IE1 Region, follow these steps to review the Message log in each Region:
GET
request to list your account's Messages in IE1GET
request to list your account's Messages in US1The Message you created in IE1 should not appear in the US1 Message list. Refer to the Twilio Regions introduction for a refresher on Twilio's Region isolation model.
All of Twilio's language-specific server-side helper libraries support specifying the target Region for API requests.
For example, to send a Message via the IE1 Region using the Node.js helper library, start by providing the target region
and edge
parameters to the client constructor function. Then invoke the messages.create()
method to issue the request.
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')(9apiKeySid,10apiKeySecret, {11'accountSid': accountSid,12'edge': 'dublin',13'region': 'ie1'14});1516client.messages.create({17body: 'Ahoy from Ireland!',18to: toNumber,19from: fromNumber,20}).then((message) => console.log(message));
Well done! You've successfully sent an SMS message with Twilio's API using the Twilio IE1 Region.
Outbound messaging functionality in the IE1 Region is currently available as a private pilot program and is subject to the following limitations.