Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Messaging Service ShortCode Resource


(warning)

Public Beta

The Service Resource is currently available as a Public Beta product. This means that some features for configuring your Messaging Service via the REST API are not yet implemented, and others may be changed before the product is declared Generally Available. Messaging Service Configuration through the Twilio Console is Generally Available.

Public Beta products are not covered by a Twilio SLA.

The resources for sending Messages with a Messaging Service are Generally Available.

The ShortCode subresource of a Service Resource represents the short codes you have associated to the Service.

When a short code has been added to the Messaging Service, Twilio always prioritizes message delivery with your short code when possible. If the short code cannot be used to reach your user, Twilio performs a Short Code Reroute to sent the message from a long code in your Messaging Service instead.

Inbound messages received on any of short codes associated with a Messaging Service are passed to the inbound request URL of the Service with the TWiML parameters that describe the message.


ShortCode Properties

Property nameTypePIIDescription
sidSID<SC>
Not PII

The unique string that we created to identify the ShortCode resource.

Pattern: ^SC[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

The SID of the Account that created the ShortCode resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

service_sidSID<MG>

The SID of the Service the resource is associated with.

Pattern: ^MG[0-9a-fA-F]{32}$Min length: 34Max length: 34

date_createdstring<date-time>

The date and time in GMT when the resource was created specified in ISO 8601 format.


date_updatedstring<date-time>

The date and time in GMT when the resource was last updated specified in ISO 8601 format.


short_codestring

The E.164 format of the short code.


country_codestring

The 2-character ISO Country Code of the number.


capabilitiesarray[string]

An array of values that describe whether the number can receive calls or messages. Can be: SMS and MMS.


urlstring<uri>

The absolute URL of the ShortCode resource.


Create a ShortCode resource

POST https://messaging.twilio.com/v1/Services/{ServiceSid}/ShortCodes

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to create the resource under.

Pattern: ^MG[0-9a-fA-F]{32}$Min length: 34Max length: 34

Request body parameters

Property nameTypeRequiredPIIDescription
ShortCodeSidSID<SC>required

The SID of the ShortCode resource being added to the Service.

Pattern: ^SC[0-9a-fA-F]{32}$Min length: 34Max length: 34

Create a ShortCode

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function createShortCode() {
_18
const shortCode = await client.messaging.v1
_18
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.shortCodes.create({ shortCodeSid: "SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" });
_18
_18
console.log(shortCode.sid);
_18
}
_18
_18
createShortCode();

Output

_13
{
_13
"sid": "SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_13
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_13
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_13
"date_created": "2015-07-30T20:12:31Z",
_13
"date_updated": "2015-07-30T20:12:33Z",
_13
"short_code": "12345",
_13
"country_code": "US",
_13
"capabilities": [
_13
"SMS"
_13
],
_13
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes/SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_13
}


Fetch a ShortCode resource

GET https://messaging.twilio.com/v1/Services/{ServiceSid}/ShortCodes/{Sid}

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to fetch the resource from.

Pattern: ^MG[0-9a-fA-F]{32}$Min length: 34Max length: 34

Sidstringrequired

The SID of the ShortCode resource to fetch.

Fetch a ShortCode

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function fetchShortCode() {
_19
const shortCode = await client.messaging.v1
_19
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.shortCodes("Sid")
_19
.fetch();
_19
_19
console.log(shortCode.sid);
_19
}
_19
_19
fetchShortCode();

Output

_13
{
_13
"sid": "Sid",
_13
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_13
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_13
"date_created": "2015-07-30T20:12:31Z",
_13
"date_updated": "2015-07-30T20:12:33Z",
_13
"short_code": "12345",
_13
"country_code": "US",
_13
"capabilities": [
_13
"SMS"
_13
],
_13
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes/SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_13
}


Read multiple ShortCode resources

GET https://messaging.twilio.com/v1/Services/{ServiceSid}/ShortCodes

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to read the resources from.

Pattern: ^MG[0-9a-fA-F]{32}$Min length: 34Max length: 34

Query parameters

Property nameTypeRequiredPIIDescription
PageSizeintegerOptional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

PageintegerOptional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

List multiple ShortCodes

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function listShortCode() {
_18
const shortCodes = await client.messaging.v1
_18
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.shortCodes.list({ limit: 20 });
_18
_18
shortCodes.forEach((s) => console.log(s.sid));
_18
}
_18
_18
listShortCode();

Output

_26
{
_26
"meta": {
_26
"page": 0,
_26
"page_size": 20,
_26
"first_page_url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes?PageSize=20&Page=0",
_26
"previous_page_url": null,
_26
"next_page_url": null,
_26
"key": "short_codes",
_26
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes?PageSize=20&Page=0"
_26
},
_26
"short_codes": [
_26
{
_26
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"sid": "SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"date_created": "2015-07-30T20:12:31Z",
_26
"date_updated": "2015-07-30T20:12:33Z",
_26
"short_code": "12345",
_26
"country_code": "US",
_26
"capabilities": [
_26
"SMS"
_26
],
_26
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes/SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_26
}
_26
]
_26
}


Delete a ShortCode resource

DELETE https://messaging.twilio.com/v1/Services/{ServiceSid}/ShortCodes/{Sid}

(warning)

Warning

Removing a short code from the Messaging Service does not release the short code from your account. You must cancel the short code from your Account in order to disassociate and delete the short code from your Messaging Service.

Returns a 204 NO CONTENT if the short code was successfully removed from the service.

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to delete the resource from.

Pattern: ^MG[0-9a-fA-F]{32}$Min length: 34Max length: 34

Sidstringrequired

The SID of the ShortCode resource to delete.

Delete a ShortCode

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_17
// Download the helper library from https://www.twilio.com/docs/node/install
_17
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_17
_17
// Find your Account SID and Auth Token at twilio.com/console
_17
// and set the environment variables. See http://twil.io/secure
_17
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_17
const authToken = process.env.TWILIO_AUTH_TOKEN;
_17
const client = twilio(accountSid, authToken);
_17
_17
async function deleteShortCode() {
_17
await client.messaging.v1
_17
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_17
.shortCodes("Sid")
_17
.remove();
_17
}
_17
_17
deleteShortCode();


Rate this page: