Skip to contentSkip to navigationSkip to topbar
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(link takes you to an external page) is Generally Available.

Public Beta products are not covered by a Twilio SLA(link takes you to an external page).

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

shortcode-properties page anchor
Property nameTypeRequiredDescriptionChild properties
sidSID<SC>Optional
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>Optional

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>Optional

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>Optional

The date and time in GMT when the resource was created specified in ISO 8601(link takes you to an external page) format.


date_updatedstring<date-time>Optional

The date and time in GMT when the resource was last updated specified in ISO 8601(link takes you to an external page) format.


short_codestringOptional

The E.164 format of the short code.


country_codestringOptional

capabilitiesarray[string]Optional

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


urlstring<uri>Optional

The absolute URL of the ShortCode resource.


Create a ShortCode resource

create-a-shortcode-resource page anchor
POST https://messaging.twilio.com/v1/Services/{ServiceSid}/ShortCodes

Path parameters

path-parameters page anchor
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
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
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
Add a Short Code to a Messaging ServiceLink to code sample: Add a Short Code to a Messaging Service
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createShortCode() {
11
const shortCode = await client.messaging.v1
12
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.shortCodes.create({ shortCodeSid: "SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" });
14
15
console.log(shortCode.sid);
16
}
17
18
createShortCode();

Output

1
{
2
"sid": "SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"date_created": "2015-07-30T20:12:31Z",
6
"date_updated": "2015-07-30T20:12:33Z",
7
"short_code": "12345",
8
"country_code": "US",
9
"capabilities": [
10
"SMS"
11
],
12
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes/SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
13
}

Fetch a ShortCode resource

fetch-a-shortcode-resource page anchor
GET https://messaging.twilio.com/v1/Services/{ServiceSid}/ShortCodes/{Sid}

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 Short Code from a Messaging ServiceLink to code sample: Fetch a Short Code from a Messaging Service
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchShortCode() {
11
const shortCode = await client.messaging.v1
12
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.shortCodes("SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.fetch();
15
16
console.log(shortCode.sid);
17
}
18
19
fetchShortCode();

Output

1
{
2
"sid": "SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"date_created": "2015-07-30T20:12:31Z",
6
"date_updated": "2015-07-30T20:12:33Z",
7
"short_code": "12345",
8
"country_code": "US",
9
"capabilities": [
10
"SMS"
11
],
12
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes/SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
13
}

Read multiple ShortCode resources

read-multiple-shortcode-resources page anchor
GET https://messaging.twilio.com/v1/Services/{ServiceSid}/ShortCodes

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

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listShortCode() {
11
const shortCodes = await client.messaging.v1
12
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.shortCodes.list({ limit: 20 });
14
15
shortCodes.forEach((s) => console.log(s.sid));
16
}
17
18
listShortCode();

Output

1
{
2
"meta": {
3
"page": 0,
4
"page_size": 20,
5
"first_page_url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes?PageSize=20&Page=0",
6
"previous_page_url": null,
7
"next_page_url": null,
8
"key": "short_codes",
9
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes?PageSize=20&Page=0"
10
},
11
"short_codes": [
12
{
13
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"sid": "SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"date_created": "2015-07-30T20:12:31Z",
17
"date_updated": "2015-07-30T20:12:33Z",
18
"short_code": "12345",
19
"country_code": "US",
20
"capabilities": [
21
"SMS"
22
],
23
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes/SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
24
}
25
]
26
}

Delete a ShortCode resource

delete-a-shortcode-resource page anchor
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.

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 Short Code from a Messaging ServiceLink to code sample: Delete a Short Code from a Messaging Service
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteShortCode() {
11
await client.messaging.v1
12
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.shortCodes("SCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.remove();
15
}
16
17
deleteShortCode();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.