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

Command Resource


The Command resource enables you to exchange simple machine-to-machine messages with SMS-capable devices. For example, you could use a Command resource to instruct a device to take a sensor reading.

While SMS is used as the transport, the SIM does not require an addressable phone number to receive a Command. This is the major distinction from Twilio's Messages resource, which can be used for conversational messaging.

Any SMS message sent from a SIM to a pre-determined phone number — see Receive a Command from a SIM — is interpreted as a Command and sent to the Command callback URL of the Sim resource.

Commands can be sent and received using the SMS text mode or binary (PDU) mode. Text-mode Commands have a maximum length of 160 single-byte characters. Binary-mode Commands have a maximum length of 140 bytes.

To receive and process a Command sent to your device, you will interface with the modem directly, probably using AT commands. You should consult with the module manufacturer's documentation for information about receiving SMS messages.


Asynchronous resources

asynchronous-resources page anchor

The Command resource performs asynchronous operations. To receive an asynchronous notification when a Command resource has finished updating, provide a callback URL, and optionally a callback method, GET or POST, when you create the Command.


Commands are retained for 30 days from the time they are created. Commands older than 30 days will no longer be readable from this resource.


Resource properties
sidtype: SID<DC>Not PII

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


sim_sidtype: SID<DE>Not PII

The SID of the Sim resource(link takes you to an external page) that the Command was sent to or from.


commandtype: stringPII MTL: 30 days

The message being sent to or from the SIM. For text mode messages, this can be up to 160 characters. For binary mode messages, this is a series of up to 140 bytes of data encoded using base64.


command_modetype: enum<STRING>Not PII

The mode used to send the SMS message. Can be: text or binary. The default SMS mode is text.

Possible values:
textbinary

transporttype: enum<STRING>Not PII

The type of transport used. Can be: sms or ip.

Possible values:
smsip

delivery_receipt_requestedtype: booleanNot PII

Whether to request a delivery receipt.


statustype: enum<STRING>Not PII

The status of the Command. Can be: queued, sent, delivered, received, or failed. See Status Values(link takes you to an external page) for a description of each state.

Possible values:
queuedsentdeliveredreceivedfailed

directiontype: enum<STRING>Not PII

The direction of the Command. Can be to_sim or from_sim. The value of to_sim is synonymous with the term mobile terminated, and from_sim is synonymous with the term mobile originated.

Possible values:
from_simto_sim

date_createdtype: string<DATE TIME>Not PII

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


date_updatedtype: string<DATE TIME>Not PII

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


urltype: string<URI>Not PII

The absolute URL of the resource.

Status values

status-values page anchor
StatusDescription
queuedThe Command is queued in our network waiting to be sent to the SIM.
sentThe Command has been sent to the SIM.
deliveredThe Command has been delivered to the SIM. For to_sim Commands only.
receivedThe Command has been received from the SIM. For from_sim Commands only.
failedThe Command has failed to be transmitted.

Create a Command resource

create-a-command-resource page anchor
POST https://wireless.twilio.com/v1/Commands

Creating a Command resource sends the command to the SIM.

Outgoing Command delivery is asynchronous, so we recommend that you pass a callback URL when you create the new Command.

When you provide a callback URL, we call it when the attempt to send the Command completes.

We send these parameters to the callback URL:

ParameterDescription
CommandSidThe Command this callback is in reference to.
CommandStatusThe current status of the Command.
SimSidThe SIM this Command was sent to.
SimUniqueNameThe receiving SIM's UniqueName, if it has one.
ErrorCodeIf an error occurred, an error code is provided.
ErrorMessageIf an error occurred, an error message is provided.
ApiVersionThe version of the API that your initial request was made to.
AccountSidThe SID of the Account that this Command belongs to.
CommandModeA string representing which mode the SMS was sent using. May be text or binary.

If the CallbackMethod parameter was set to POST, or not provided, the callback parameters are delivered as HTML form parameters. If the CallbackMethod parameter was set to GET, the callback parameters are delivered as a query string.

Parameters

create-parameters page anchor
Request body parameters
Commandtype: stringPII MTL: 30 days
Required

The message body of the Command. Can be plain text in text mode or a Base64 encoded byte string in binary mode.


Simtype: stringNot PII

The sid or unique_name of the SIM(link takes you to an external page) to send the Command to.


CallbackMethodtype: enum<HTTP METHOD>Not PII

The HTTP method we use to call callback_url. Can be: POST or GET, and the default is POST.

Possible values:
HEADGETPOSTPATCHPUTDELETE

CallbackUrltype: string<URI>Not PII

The URL we call using the callback_url when the Command has finished sending, whether the command was delivered or it failed.


CommandModetype: enum<STRING>Not PII

The mode to use when sending the SMS message. Can be: text or binary. The default SMS mode is text.

Possible values:
textbinary

IncludeSidtype: stringNot PII

Whether to include the SID of the command in the message body. Can be: none, start, or end, and the default behavior is none. When sending a Command to a SIM in text mode, we can automatically include the SID of the Command in the message body, which could be used to ensure that the device does not process the same Command more than once. A value of start will prepend the message with the Command SID, and end will append it to the end, separating the Command SID from the message body with a space. The length of the Command SID is included in the 160 character limit so the SMS body must be 128 characters or less before the Command SID is included.


DeliveryReceiptRequestedtype: booleanNot PII

Whether to request delivery receipt from the recipient. For Commands that request delivery receipt, the Command state transitions to 'delivered' once the server has received a delivery receipt from the device. The default value is true.

Create a text Command resource

create-a-text-command-resource page anchor

Send the ‘wakeup' command to the ‘AliceSmithSmartMeter' SIM

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

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.wireless.v1.commands
_10
.create({sim: 'AliceSmithSmartMeter', command: 'wakeup'})
_10
.then(command => console.log(command.sid));

Output

_14
{
_14
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"command": "wakeup",
_14
"command_mode": "text",
_14
"date_created": "2015-07-30T20:00:00Z",
_14
"date_updated": "2015-07-30T20:00:00Z",
_14
"delivery_receipt_requested": true,
_14
"sim_sid": "DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"direction": "from_sim",
_14
"sid": "DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"status": "queued",
_14
"transport": "sms",
_14
"url": "https://wireless.twilio.com/v1/Commands/DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_14
}

Create a binary Command resource

create-a-binary-command-resource page anchor

Send a binary command to the ‘AliceSmithSmartMeter' SIM

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

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = require('twilio')(accountSid, authToken);
_14
_14
client.wireless.v1.commands
_14
.create({
_14
sim: 'AliceSmithSmartMeter',
_14
commandMode: 'binary',
_14
command: 'SGVsbG8sIE1hY2hpbmUh=='
_14
})
_14
.then(command => console.log(command.sid));

Output

_14
{
_14
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"command": "SGVsbG8sIE1hY2hpbmUh==",
_14
"command_mode": "binary",
_14
"date_created": "2015-07-30T20:00:00Z",
_14
"date_updated": "2015-07-30T20:00:00Z",
_14
"delivery_receipt_requested": true,
_14
"sim_sid": "DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"direction": "from_sim",
_14
"sid": "DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"status": "queued",
_14
"transport": "sms",
_14
"url": "https://wireless.twilio.com/v1/Commands/DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_14
}


Fetch a Command resource

fetch-a-command-resource page anchor
GET https://wireless.twilio.com/v1/Commands/{Sid}

URI parameters
Sidtype: SID<DC>Not PII
Path Parameter

The SID of the Command resource to fetch.

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

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.wireless.v1.commands('DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_10
.fetch()
_10
.then(command => console.log(command.sid));

Output

_14
{
_14
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"command": "command",
_14
"command_mode": "text",
_14
"date_created": "2015-07-30T20:00:00Z",
_14
"date_updated": "2015-07-30T20:00:00Z",
_14
"delivery_receipt_requested": true,
_14
"sim_sid": "DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"direction": "from_sim",
_14
"sid": "DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"status": "queued",
_14
"transport": "sms",
_14
"url": "https://wireless.twilio.com/v1/Commands/DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_14
}


Read multiple Command resources

read-multiple-command-resources page anchor
GET https://wireless.twilio.com/v1/Commands

(warning)

Warning

The maximum PageSize you can request when reading Commands is 100.

URI parameters
Simtype: stringNot PII
Query Parameter

The sid or unique_name of the Sim resources(link takes you to an external page) to read.


Statustype: enum<STRING>Not PII
Query Parameter

The status of the resources to read. Can be: queued, sent, delivered, received, or failed.

Possible values:
queuedsentdeliveredreceivedfailed

Directiontype: enum<STRING>Not PII
Query Parameter

Only return Commands with this direction value.

Possible values:
from_simto_sim

Transporttype: enum<STRING>Not PII
Query Parameter

Only return Commands with this transport value. Can be: sms or ip.

Possible values:
smsip

PageSizetype: integerNot PII
Query Parameter

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


Pagetype: integerNot PII
Query Parameter

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


PageTokentype: stringNot PII
Query Parameter

The page token. This is provided by the API.

Read multiple Command resources

read-multiple-command-resources-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.wireless.v1.commands
_10
.list({limit: 20})
_10
.then(commands => commands.forEach(c => console.log(c.sid)));

Output

_12
{
_12
"commands": [],
_12
"meta": {
_12
"first_page_url": "https://wireless.twilio.com/v1/Commands?Status=queued&Direction=from_sim&Sim=sim&PageSize=50&Page=0",
_12
"key": "commands",
_12
"next_page_url": "https://wireless.twilio.com/v1/Commands?Status=queued&Direction=from_sim&Sim=sim&PageSize=50&Page=1",
_12
"page": 0,
_12
"page_size": 50,
_12
"previous_page_url": "https://wireless.twilio.com/v1/Commands?Status=queued&Direction=from_sim&Sim=sim&PageSize=50&Page=0",
_12
"url": "https://wireless.twilio.com/v1/Commands?Status=queued&Direction=from_sim&Sim=sim&PageSize=50&Page=0"
_12
}
_12
}


Delete a Command resource

delete-a-command-resource page anchor
DELETE https://wireless.twilio.com/v1/Commands/{Sid}

URI parameters
Sidtype: SID<DC>Not PII
Path Parameter

The SID of the Command resource to delete.

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

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.wireless.v1.commands('DCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove();


Receive a Command from a SIM

receive-a-command-from-a-sim page anchor

To receive a Command from a SIM — called a "mobile-originated" Command — you should create or update an existing Sim instance and provide a CommandsCallbackUrl property. Optionally, you may also include a CommandsCallbackMethod property.

When a SIM sends an SMS message to the reserved phone number 2936, a Command resource will be created, and your Commands Callback URL will be invoked. The callback request will include the following parameters.

ParameterDescription
CommandSidThe SID of this Command.
SimSidThe SIM this Command was sent by.
SimUniqueNameThe sending SIM's friendly name, if it has one.
CommandThe body of the Command message. In text mode, this value can be up to 160 characters of text. In binary mode, this value is a Base64 encoded byte string with a maximum size of 140 bytes.
StatusWill always be the string received.
ApiVersionThe version of the API that your initial request was made to.
AccountSidThe SID of the Account that this Command belongs to.
CommandModeA string representing which mode the SMS was received as. May be text or binary.

Rate this page: