This page covers how to use Twilio's REST API to configure a SIP Trunk Phone Number's emergency Address. Before proceeding, you must read the SIP Trunking Emergency Calling doc.
Don't want to use the REST API? You can also use the Console to configure emergency calling Addresses. See the SIP Trunking Emergency Calling doc for more information.
Before you can configure a Twilio Phone Number for emergency calling, you need to create an emergency Address. An emergency Address is an Address resource with the emergency_enabled
property set to true
.
You can use the same emergency Address for multiple Phone Numbers if appropriate.
To create a new emergency Address resource via REST API, create a new Address resource with the emergency_enabled
parameter set to true
. An example request is shown below.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createAddress() {11const address = await client.addresses.create({12city: "San Francisco",13customerName: "Twilio",14emergencyEnabled: true,15friendlyName: "Twilio",16isoCountry: "US",17postalCode: "94105",18region: "CA",19street: "645 Harrison St.",20});2122console.log(address.accountSid);23}2425createAddress();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"city": "San Francisco",4"customer_name": "Twilio",5"date_created": "Tue, 18 Aug 2015 17:07:30 +0000",6"date_updated": "Tue, 18 Aug 2015 17:07:30 +0000",7"emergency_enabled": true,8"friendly_name": "Twilio",9"iso_country": "US",10"postal_code": "94105",11"region": "CA",12"sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",13"street": "645 Harrison St.",14"street_secondary": null,15"validated": false,16"verified": false,17"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Addresses/ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"18}
The response to this request contains a sid
property. This is the Address's SID, which you need when configuring your Phone Numbers.
If you already have an Address resource you wish to use as an emergency Address, update the Address resource so that the emergency_enabled
property is true
as shown in the example below.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateAddress() {11const address = await client12.addresses("ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.update({ emergencyEnabled: true });1415console.log(address.accountSid);16}1718updateAddress();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"city": "SF",4"customer_name": "name",5"date_created": "Tue, 18 Aug 2015 17:07:30 +0000",6"date_updated": "Tue, 18 Aug 2015 17:07:30 +0000",7"emergency_enabled": true,8"friendly_name": null,9"iso_country": "US",10"postal_code": "94019",11"region": "CA",12"sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",13"street": "4th",14"street_secondary": null,15"validated": false,16"verified": false,17"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Addresses/ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"18}
Once you've created an emergency Address, you need to update the IncomingPhoneNumber resource's emergency_address_sid
property with the emergency Address SID, as shown in the code sample below.
This request requires the SID of the Phone Number. You can find the SIDs of your SIP Trunk's Phone Numbers using the PhoneNumber Subresource.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateIncomingPhoneNumber() {11const incomingPhoneNumber = await client12.incomingPhoneNumbers("PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.update({ emergencyAddressSid: "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" });1415console.log(incomingPhoneNumber.accountSid);16}1718updateIncomingPhoneNumber();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"address_requirements": "none",4"address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"api_version": "2010-04-01",6"beta": false,7"capabilities": {8"voice": true,9"sms": false,10"mms": true,11"fax": false12},13"date_created": "Thu, 30 Jul 2015 23:19:04 +0000",14"date_updated": "Thu, 30 Jul 2015 23:19:04 +0000",15"emergency_status": "Inactive",16"emergency_address_sid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",17"emergency_address_status": "registered",18"friendly_name": "(808) 925-5327",19"identity_sid": "RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",20"origin": "origin",21"phone_number": "+18089255327",22"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",23"sms_application_sid": "",24"sms_fallback_method": "POST",25"sms_fallback_url": "",26"sms_method": "POST",27"sms_url": "",28"status_callback": "",29"status_callback_method": "POST",30"trunk_sid": null,31"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",32"voice_application_sid": "",33"voice_caller_id_lookup": true,34"voice_fallback_method": "POST",35"voice_fallback_url": null,36"voice_method": "POST",37"voice_url": null,38"voice_receive_mode": "voice",39"status": "in-use",40"bundle_sid": "BUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",41"subresource_uris": {42"assigned_add_ons": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AssignedAddOns.json"43}44}
You can check on the status of a Phone Number's emergency Address registration by fetching the IncomingPhoneNumber resource and checking the value of the emergency_address_status
property. An example of this request is shown below.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchIncomingPhoneNumber() {11const incomingPhoneNumber = await client12.incomingPhoneNumbers("PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.fetch();1415console.log(incomingPhoneNumber.accountSid);16}1718fetchIncomingPhoneNumber();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"address_requirements": "none",4"address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"api_version": "2010-04-01",6"beta": false,7"capabilities": {8"voice": true,9"sms": false,10"mms": true,11"fax": false12},13"date_created": "Thu, 30 Jul 2015 23:19:04 +0000",14"date_updated": "Thu, 30 Jul 2015 23:19:04 +0000",15"emergency_status": "Active",16"emergency_address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",17"emergency_address_status": "registered",18"friendly_name": "(808) 925-5327",19"identity_sid": "RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",20"origin": "origin",21"phone_number": "+18089255327",22"sid": "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",23"sms_application_sid": "",24"sms_fallback_method": "POST",25"sms_fallback_url": "",26"sms_method": "POST",27"sms_url": "",28"status_callback": "",29"status_callback_method": "POST",30"trunk_sid": null,31"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",32"voice_application_sid": "",33"voice_caller_id_lookup": false,34"voice_fallback_method": "POST",35"voice_fallback_url": null,36"voice_method": "POST",37"voice_url": null,38"voice_receive_mode": "voice",39"status": "in-use",40"bundle_sid": "BUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",41"subresource_uris": {42"assigned_add_ons": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AssignedAddOns.json"43}44}
To remove an emergency Address from a Phone Number, you need to remove the emergency_address_sid
from the IncomingPhoneNumber resource as shown in the example below.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateIncomingPhoneNumber() {11const incomingPhoneNumber = await client12.incomingPhoneNumbers("PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.update({ emergencyAddressSid: "" });1415console.log(incomingPhoneNumber.accountSid);16}1718updateIncomingPhoneNumber();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"address_requirements": "none",4"address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"api_version": "2010-04-01",6"beta": false,7"capabilities": {8"voice": true,9"sms": false,10"mms": true,11"fax": false12},13"date_created": "Thu, 30 Jul 2015 23:19:04 +0000",14"date_updated": "Thu, 30 Jul 2015 23:19:04 +0000",15"emergency_status": "Inactive",16"emergency_address_sid": "",17"emergency_address_status": "registered",18"friendly_name": "(808) 925-5327",19"identity_sid": "RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",20"origin": "origin",21"phone_number": "+18089255327",22"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",23"sms_application_sid": "",24"sms_fallback_method": "POST",25"sms_fallback_url": "",26"sms_method": "POST",27"sms_url": "",28"status_callback": "",29"status_callback_method": "POST",30"trunk_sid": null,31"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",32"voice_application_sid": "",33"voice_caller_id_lookup": true,34"voice_fallback_method": "POST",35"voice_fallback_url": null,36"voice_method": "POST",37"voice_url": null,38"voice_receive_mode": "voice",39"status": "in-use",40"bundle_sid": "BUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",41"subresource_uris": {42"assigned_add_ons": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AssignedAddOns.json"43}44}
After this request, you should check the emergency Address registration status of the Phone Number to ensure the de-registration of that emergency Address.
To change a Phone Number's emergency Address, you need to follow the steps listed below.
emergency_address_sid
from the IncomingPhoneNumber resource.emergency_address_status
is unregistered
before proceeding.emergency_address_sid
with the new emergency Address SID.emergency_address_status
is registered
, the Phone Number has been successfully updated.If you wish to delete an emergency Address, you must first make sure that it is no longer associated with any IncomingPhoneNumber resources (or any other Twilio resource).
You can then delete the Address resource, as shown in the sample request below.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deleteAddress() {11await client.addresses("ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").remove();12}1314deleteAddress();