Skip to contentSkip to navigationSkip to topbar
On this page

Send an SMS Message via REST API in a non-US Twilio Region


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.


Step 1: Setup

step-1-setup page anchor

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:

  1. Log in to the Twilio Console(link takes you to an external page).
  2. Click the Account menu in the upper right corner of the screen.
  3. Click API keys & tokens , under the Keys & Credentials heading.
  4. Select Ireland (IE1) from the Region dropdown list.
  5. Click the blue Create API key button.
  6. Enter a friendly name for the key (example: "Send an SMS with Twilio Regions").
  7. Leave Key Type on the default option, "Standard".
  8. Click the blue Create API Key button.

Make a note of the API Key's SID and Secret . You will need this information during the next step.


Step 2: Make a request to the Messages endpoint in IE1

step-2-make-a-request-to-the-messages-endpoint-in-ie1 page anchor

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.

(warning)

Warning

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
(information)

Info

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.

Send the request using cURL

send-the-request-using-curl page anchor

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.

1
export ACCOUNT_SID=<your_account_sid_here>
2
export API_KEY_SID=<your_api_key_sid_here>
3
export API_KEY_SECRET=<your_api_key_secret_here>
4
5
export TO_NUMBER=<your_to_number_here>
6
export 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.

1
curl -X POST \
2
-u $API_KEY_SID:$API_KEY_SECRET \
3
https://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:

  • Make a GET request to list your account's Messages in IE1
  • Make a GET request to list your account's Messages in US1
  • Compare the results

The 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.


Step 3 (optional): Make the API request using a Twilio helper library

step-3-optional-make-the-api-request-using-a-twilio-helper-library page anchor

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.

1
const accountSid = process.env.ACCOUNT_SID;
2
const apiKeySid = process.env.API_KEY_SID;
3
const apiKeySecret = process.env.API_KEY_SECRET;
4
5
const toNumber = process.env.TO_NUMBER;
6
const fromNumber = process.env.FROM_NUMBER;
7
8
const client = require('twilio')(
9
apiKeySid,
10
apiKeySecret, {
11
'accountSid': accountSid,
12
'edge': 'dublin',
13
'region': 'ie1'
14
});
15
16
client.messages.create({
17
body: 'Ahoy from Ireland!',
18
to: toNumber,
19
from: 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.

  • The authenticating account must be enrolled in the pilot program
  • Messages can only be delivered to supported destination countries
  • MMS messages are not supported
  • Messaging Services are not supported
  • The IE1 Message Log interface in Twilio Console is not available