Sending and managing messages
This article details commonly used API operations. Each section corresponds to an operation and includes a brief overview, a sample request and response payload, and schema information pulled directly from the API reference. Additionally, each section will include links to the corresponding API reference entry and any tutorials (if available).
Note:
For information on how complete the configuration steps required for this API, along with language-specific guides that illustrate the API's functionality with pre-populated examples, see the Getting started guides that correspond to this API.
The SMS REST API enables users to send, retreive, update and delete messages to one or more recipient(s) using batches. In simple terms, a batch consists of the message you want to send, your Sinch mobile number, and a list of recipients. With batches, you can do everything from appointment scheduling to marketing campaigns.
Sending a message
This endpoint enables you to send messages. As well as sending messages to multiple recipients, it allows users to schedule messages and even set an expiry date. This is useful for applications which require messages to be sent at particular times, such as appointment scheduling or marketing campaigns.
Note
Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Payload
- Node.js
- C#
- Java
- Python
- curl
- PHP
{- "from": "YOUR_Sinch_virtual_number",
- "to": [
- "YOUR_recipient_number"
], - "body": "YOUR_message_body",
- "type": "mt_text"
}
TextRequest
schema below:See the schema
Sample response
After making this API call, you should receive a response that is similar to the example given below:
{- "id": "01FC66621XXXXX119Z8PMV1QPQ",
- "to": [
- 15551231234,
- 15551256344
], - "from": 15551231234,
- "canceled": false,
- "parameters": {
- "{parameter_key}": {
- "{msisdn}": 15551231234,
- "default": "string"
}
}, - "body": "Hi ${name}! How are you?",
- "type": "mt_text",
- "created_at": "2019-08-24T14:15:22Z",
- "modified_at": "2019-08-24T14:15:22Z",
- "delivery_report": "none",
- "send_at": "2019-08-24T14:15:22Z",
- "expire_at": "2019-08-24T14:15:22Z",
- "callback_url": "myCallbackUrl",
- "client_reference": "myReference",
- "feedback_enabled": false,
- "flash_message": false,
- "truncate_concat": true,
- "max_number_of_message_parts": 1,
- "from_ton": 6,
- "from_npi": 18
}
TextResponse
schema below:See the schema
type required | string Regular SMS
| ||||||||||
id | string Unique identifier for batch | ||||||||||
to | Array of strings <E.164> (MtDestination) [ 1 .. 1000 ] items List of Phone numbers and group IDs that will receive the batch. More info | ||||||||||
from | string Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic Default Originator not configured. | ||||||||||
canceled | boolean Default: false Indicates if the batch has been canceled or not. | ||||||||||
object (parameterObj) Contains the parameters that will be used for customizing the message for each recipient. | |||||||||||
body | string [ 0 .. 2000 ] characters The message content | ||||||||||
created_at | string <date-time> Timestamp for when batch was created. Formatted as ISO-8601: | ||||||||||
modified_at | string <date-time> Timestamp for when batch was last updated. Formatted as ISO-8601: | ||||||||||
delivery_report | string (DeliveryReportType) Kind of delivery report
| ||||||||||
send_at | string <date-time> If set in the future, the message will be delayed until | ||||||||||
expire_at | string <date-time> If set, the system will stop trying to deliver the message at this point. Must be after | ||||||||||
callback_url | string [ 0 .. 2048 ] characters Override the default callback URL for this batch. Must be valid URL. | ||||||||||
client_reference | string [ 0 .. 2048 ] characters The client identifier of a batch message. If set, the identifier will be added in the delivery report/callback of this batch | ||||||||||
feedback_enabled | |||||||||||
flash_message | boolean Default: false Shows message on screen without user interaction while not saving the message to the inbox. | ||||||||||
truncate_concat | boolean If set to | ||||||||||
max_number_of_message_parts | integer <int32> >= 1 Message will be dispatched only if it is not split to more parts than Max Number of Message Parts | ||||||||||
from_ton | integer <int32> [ 0 .. 6 ] The type of number for the sender number. Use to override the automatic detection. | ||||||||||
from_npi | integer <int32> [ 0 .. 18 ] Number Plan Indicator for the sender number. Use to override the automatic detection. |
Performing a dry run for a batch of recipients
This operation will perform a dry run of a batch which calculates the bodies and number of parts for all messages in the batch without actually sending any messages. If you are a new Sinch user, the Dry Run operation is perfect for testing how to send a message as it incurrs no costs. For existing users, the Dry Run operation is very useful for testing SMS marketing campaigns designed to engage high volumes of users and making sure there are no errors.
Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Payload
- Node.js
- C#
- Java
- Python
- curl
- PHP
{- "from": "YOUR_virtual_number",
- "to": [
- "YOUR_numbers_sending_to",
- "another_number"
], - "body": "YOUR body text here",
- "parameters": {
- "name": {
- "Phone_number_of_recipient": "recipient_name",
- "default": "default_in_place_of_name"
}
}
}
TextRequest
schema below:See the schema
Sample response
After making this API call, you should receive a response that is similar to the example given below:
{- "number_of_recipients": 1,
- "number_of_messages": 1,
- "per_recipient": [
- {
- "recipient": 15551231234,
- "number_of_parts": 1,
- "body": "Test Message",
- "encoding": "GSM"
}
]
}
For the full schema of the response that corresponds to this API call, see the corresponding entry in the API reference. Alternatively, expand the schema below:
See the schema
number_of_recipients | integer The number of recipients in the batch |
number_of_messages | integer The total number of SMS message parts to be sent in the batch |
Array of objects The recipient, the number of message parts to this recipient, the body of the message, and the encoding type of each message |
Retrieving a list of batches
The list operation enables you to list batch messages that you have created in the last 14 days. This operation is highly customizable. Users can filter results by date range andfrom
number. If there is a high volume of batches, results can be paginated. Pagination is flexible, with the page
and page_size
query parameters enabling users to set the number of pages and the number of results per page.Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Node.js
- C#
- Java
- Python
- curl
- PHP
For the full schema of this API call, see the corresponding entry.
Sample response
After making this API call, you should receive a response that is similar to the example given below:
{- "count": "2",
- "page": "1",
- "batches": [
- {
- "id": "abc123",
- "to": [
- "01234567"
], - "from": "01234567",
- "canceled": false,
- "body": "Test message",
- "udh": "abcxaf123",
- "type": "mt_text",
- "created_at": "2023-11-11T09:00:20.0",
- "modified_at": "2023-11-11T09:00:20.0",
- "delivery_report": "none",
- "send_at": "2023-11-11T09:00:20.0",
- "expire_at": "",
- "callback_url": "",
- "client_reference": "xyz",
- "feedback_enabled": false,
- "flash_message": false,
- "truncate_concat": "false",
- "max_number_of_message_parts": "1",
- "from_ton": "0",
- "from_npi": "0"
}, - {
- "id": "def345",
- "to": [
- "07654321"
], - "from": "012346790",
- "canceled": false,
- "body": "Test Message 2",
- "udh": "abcxaf123",
- "type": "mt_text",
- "created_at": "2023-11-11T09:00:20.0",
- "modified_at": "2023-11-11T09:00:20.0",
- "delivery_report": "none",
- "send_at": "2023-11-11T09:00:20.0",
- "expire_at": "2023-11-11T09:00:20.0",
- "callback_url": "",
- "client_reference": "abc",
- "feedback_enabled": false,
- "flash_message": false,
- "truncate_concat": "false",
- "max_number_of_message_parts": "1",
- "from_ton": "0",
- "from_npi": "0"
}
], - "page_size": "10"
}
For the full schema of the response that corresponds to this API call, see the corresponding entry in the API reference. Alternatively, expand the schema below:
See the schema
count | integer <int64> The total number of entries matching the given filters. |
page | integer <int32> The requested page. |
Array of objects (Batch) The page of batches matching the given filters. | |
page_size | integer <int32> The number of entries returned in this request. |
Retrieving a message
This operation enables users to retrieve a message they created, by returning a specific batch that matches thebatch_id
provided in the path parameters. This is useful if you want to review messages to check for mistakes.Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Node.js
- C#
- Java
- Python
- curl
- PHP
For the full schema of this API call, see the corresponding entry.
Sample response
After making this API call, you should receive a response that is similar to the example given below:
{- "id": "01FC66621XXXXX119Z8PMV1QPQ",
- "to": [
- 15551231234,
- 15551256344
], - "from": 15551231234,
- "canceled": false,
- "parameters": {
- "{parameter_key}": {
- "{msisdn}": 15551231234,
- "default": "string"
}
}, - "body": "Hi ${name}! How are you?",
- "type": "mt_text",
- "created_at": "2019-08-24T14:15:22Z",
- "modified_at": "2019-08-24T14:15:22Z",
- "delivery_report": "none",
- "send_at": "2019-08-24T14:15:22Z",
- "expire_at": "2019-08-24T14:15:22Z",
- "callback_url": "myCallbackUrl",
- "client_reference": "myReference",
- "feedback_enabled": false,
- "flash_message": false,
- "truncate_concat": true,
- "max_number_of_message_parts": 1,
- "from_ton": 6,
- "from_npi": 18
}
TextResponse
schema below:See the schema
type required | string Regular SMS
| ||||||||||
id | string Unique identifier for batch | ||||||||||
to | Array of strings <E.164> (MtDestination) [ 1 .. 1000 ] items List of Phone numbers and group IDs that will receive the batch. More info | ||||||||||
from | string Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic Default Originator not configured. | ||||||||||
canceled | boolean Default: false Indicates if the batch has been canceled or not. | ||||||||||
object (parameterObj) Contains the parameters that will be used for customizing the message for each recipient. | |||||||||||
body | string [ 0 .. 2000 ] characters The message content | ||||||||||
created_at | string <date-time> Timestamp for when batch was created. Formatted as ISO-8601: | ||||||||||
modified_at | string <date-time> Timestamp for when batch was last updated. Formatted as ISO-8601: | ||||||||||
delivery_report | string (DeliveryReportType) Kind of delivery report
| ||||||||||
send_at | string <date-time> If set in the future, the message will be delayed until | ||||||||||
expire_at | string <date-time> If set, the system will stop trying to deliver the message at this point. Must be after | ||||||||||
callback_url | string [ 0 .. 2048 ] characters Override the default callback URL for this batch. Must be valid URL. | ||||||||||
client_reference | string [ 0 .. 2048 ] characters The client identifier of a batch message. If set, the identifier will be added in the delivery report/callback of this batch | ||||||||||
feedback_enabled | |||||||||||
flash_message | boolean Default: false Shows message on screen without user interaction while not saving the message to the inbox. | ||||||||||
truncate_concat | boolean If set to | ||||||||||
max_number_of_message_parts | integer <int32> >= 1 Message will be dispatched only if it is not split to more parts than Max Number of Message Parts | ||||||||||
from_ton | integer <int32> [ 0 .. 6 ] The type of number for the sender number. Use to override the automatic detection. | ||||||||||
from_npi | integer <int32> [ 0 .. 18 ] Number Plan Indicator for the sender number. Use to override the automatic detection. |
Update a batch message
The upate operation works by updating all specified parameters of a batch that matches thebatch_id
provided in the path parameters. This gives users plenty of flexibility, they can change everything from the recipients and groups the message gets sent to, to the type of delivery report. This means users can tweak campaigns they have scheduled in response to new requirements.Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Payload
- Node.js
- C#
- Java
- Python
- curl
- PHP
{- "to_remove": [
- "YOUR_numbers",
- "to_remove",
- "as_strings_in_array",
- "with_country_code",
- "16267890123"
], - "to_add": [
- "YOUR_numbers",
- "to_add"
]
}
ApiUpdateTextMtMessage
schema below:See the schema
Sample response
After making this API call, you should receive a response that is similar to the example given below:
{- "id": "01FC66621XXXXX119Z8PMV1QPQ",
- "to": [
- 15551231234,
- 15551256344
], - "from": 15551231234,
- "canceled": false,
- "parameters": {
- "{parameter_key}": {
- "{msisdn}": 15551231234,
- "default": "string"
}
}, - "body": "Hi ${name}! How are you?",
- "type": "mt_text",
- "created_at": "2019-08-24T14:15:22Z",
- "modified_at": "2019-08-24T14:15:22Z",
- "delivery_report": "none",
- "send_at": "2019-08-24T14:15:22Z",
- "expire_at": "2019-08-24T14:15:22Z",
- "callback_url": "myCallbackUrl",
- "client_reference": "myReference",
- "feedback_enabled": false,
- "flash_message": false,
- "truncate_concat": true,
- "max_number_of_message_parts": 1,
- "from_ton": 6,
- "from_npi": 18
}
TextResponse
schema below:See the schema
type required | string Regular SMS
| ||||||||||
id | string Unique identifier for batch | ||||||||||
to | Array of strings <E.164> (MtDestination) [ 1 .. 1000 ] items List of Phone numbers and group IDs that will receive the batch. More info | ||||||||||
from | string Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic Default Originator not configured. | ||||||||||
canceled | boolean Default: false Indicates if the batch has been canceled or not. | ||||||||||
object (parameterObj) Contains the parameters that will be used for customizing the message for each recipient. | |||||||||||
body | string [ 0 .. 2000 ] characters The message content | ||||||||||
created_at | string <date-time> Timestamp for when batch was created. Formatted as ISO-8601: | ||||||||||
modified_at | string <date-time> Timestamp for when batch was last updated. Formatted as ISO-8601: | ||||||||||
delivery_report | string (DeliveryReportType) Kind of delivery report
| ||||||||||
send_at | string <date-time> If set in the future, the message will be delayed until | ||||||||||
expire_at | string <date-time> If set, the system will stop trying to deliver the message at this point. Must be after | ||||||||||
callback_url | string [ 0 .. 2048 ] characters Override the default callback URL for this batch. Must be valid URL. | ||||||||||
client_reference | string [ 0 .. 2048 ] characters The client identifier of a batch message. If set, the identifier will be added in the delivery report/callback of this batch | ||||||||||
feedback_enabled | |||||||||||
flash_message | boolean Default: false Shows message on screen without user interaction while not saving the message to the inbox. | ||||||||||
truncate_concat | boolean If set to | ||||||||||
max_number_of_message_parts | integer <int32> >= 1 Message will be dispatched only if it is not split to more parts than Max Number of Message Parts | ||||||||||
from_ton | integer <int32> [ 0 .. 6 ] The type of number for the sender number. Use to override the automatic detection. | ||||||||||
from_npi | integer <int32> [ 0 .. 18 ] Number Plan Indicator for the sender number. Use to override the automatic detection. |
Replace a message batch
This operation enables a users to replace a batch wholesale. It works by replacing all the parameters of a batch with the provided values. It is the same as cancelling a batch and sending a new one instead. This is useful in situations where simply modifying an existing batch isn't enough.
Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Payload
- Node.js
- C#
- Java
- Python
- curl
- PHP
{- "to": [
- 15551231234,
- 15551256344
], - "body": "Hi ${name}! How are you?"
}
TextRequest
schema below:See the schema
Sample response
After making this API call, you should receive a response that is similar to the example given below:
{- "id": "01FC66621XXXXX119Z8PMV1QPQ",
- "to": [
- 15551231234,
- 15551256344
], - "from": 15551231234,
- "canceled": false,
- "parameters": {
- "{parameter_key}": {
- "{msisdn}": 15551231234,
- "default": "string"
}
}, - "body": "Hi ${name}! How are you?",
- "type": "mt_text",
- "created_at": "2019-08-24T14:15:22Z",
- "modified_at": "2019-08-24T14:15:22Z",
- "delivery_report": "none",
- "send_at": "2019-08-24T14:15:22Z",
- "expire_at": "2019-08-24T14:15:22Z",
- "callback_url": "myCallbackUrl",
- "client_reference": "myReference",
- "feedback_enabled": false,
- "flash_message": false,
- "truncate_concat": true,
- "max_number_of_message_parts": 1,
- "from_ton": 6,
- "from_npi": 18
}
TextResponse
schema below:See the schema
type required | string Regular SMS
| ||||||||||
id | string Unique identifier for batch | ||||||||||
to | Array of strings <E.164> (MtDestination) [ 1 .. 1000 ] items List of Phone numbers and group IDs that will receive the batch. More info | ||||||||||
from | string Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic Default Originator not configured. | ||||||||||
canceled | boolean Default: false Indicates if the batch has been canceled or not. | ||||||||||
object (parameterObj) Contains the parameters that will be used for customizing the message for each recipient. | |||||||||||
body | string [ 0 .. 2000 ] characters The message content | ||||||||||
created_at | string <date-time> Timestamp for when batch was created. Formatted as ISO-8601: | ||||||||||
modified_at | string <date-time> Timestamp for when batch was last updated. Formatted as ISO-8601: | ||||||||||
delivery_report | string (DeliveryReportType) Kind of delivery report
| ||||||||||
send_at | string <date-time> If set in the future, the message will be delayed until | ||||||||||
expire_at | string <date-time> If set, the system will stop trying to deliver the message at this point. Must be after | ||||||||||
callback_url | string [ 0 .. 2048 ] characters Override the default callback URL for this batch. Must be valid URL. | ||||||||||
client_reference | string [ 0 .. 2048 ] characters The client identifier of a batch message. If set, the identifier will be added in the delivery report/callback of this batch | ||||||||||
feedback_enabled | |||||||||||
flash_message | boolean Default: false Shows message on screen without user interaction while not saving the message to the inbox. | ||||||||||
truncate_concat | boolean If set to | ||||||||||
max_number_of_message_parts | integer <int32> >= 1 Message will be dispatched only if it is not split to more parts than Max Number of Message Parts | ||||||||||
from_ton | integer <int32> [ 0 .. 6 ] The type of number for the sender number. Use to override the automatic detection. | ||||||||||
from_npi | integer <int32> [ 0 .. 18 ] Number Plan Indicator for the sender number. Use to override the automatic detection. |
Cancel a batch message
This endpoint allows users to cancel a batch bybatch_id
provided in the path parameters. This enables a message to be cancelled before all the intended recipients receive it.Note:
If a message has already been succesfully delivered, it can't be cancelled. It's therefore advisable to cancel a scheduled batch before the message is scheduled to be sent.
Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Node.js
- C#
- Java
- Python
- curl
- PHP
For the full schema of the request that corresponds to this API call, see the corresponding entry in the API reference.
Sample response
After making this API call, you should receive a response that is similar to the example given below:
{- "id": "01FC66621XXXXX119Z8PMV1QPQ",
- "to": [
- 15551231234,
- 15551256344
], - "from": 15551231234,
- "canceled": true,
- "parameters": {
- "{parameter_key}": {
- "{msisdn}": 15551231234,
- "default": "string"
}
}, - "body": "Hi ${name}! How are you?",
- "type": "mt_text",
- "created_at": "2019-08-24T14:15:22Z",
- "modified_at": "2019-08-24T14:15:22Z",
- "delivery_report": "none",
- "send_at": "2019-08-24T14:15:22Z",
- "expire_at": "2019-08-24T14:15:22Z",
- "callback_url": "myCallbackUrl",
- "client_reference": "myReference",
- "feedback_enabled": false,
- "flash_message": false,
- "truncate_concat": true,
- "max_number_of_message_parts": 1,
- "from_ton": 6,
- "from_npi": 18
}
TextResponse
schema below:See the schema
type required | string Regular SMS
| ||||||||||
id | string Unique identifier for batch | ||||||||||
to | Array of strings <E.164> (MtDestination) [ 1 .. 1000 ] items List of Phone numbers and group IDs that will receive the batch. More info | ||||||||||
from | string Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic Default Originator not configured. | ||||||||||
canceled | boolean Default: false Indicates if the batch has been canceled or not. | ||||||||||
object (parameterObj) Contains the parameters that will be used for customizing the message for each recipient. | |||||||||||
body | string [ 0 .. 2000 ] characters The message content | ||||||||||
created_at | string <date-time> Timestamp for when batch was created. Formatted as ISO-8601: | ||||||||||
modified_at | string <date-time> Timestamp for when batch was last updated. Formatted as ISO-8601: | ||||||||||
delivery_report | string (DeliveryReportType) Kind of delivery report
| ||||||||||
send_at | string <date-time> If set in the future, the message will be delayed until | ||||||||||
expire_at | string <date-time> If set, the system will stop trying to deliver the message at this point. Must be after | ||||||||||
callback_url | string [ 0 .. 2048 ] characters Override the default callback URL for this batch. Must be valid URL. | ||||||||||
client_reference | string [ 0 .. 2048 ] characters The client identifier of a batch message. If set, the identifier will be added in the delivery report/callback of this batch | ||||||||||
feedback_enabled | |||||||||||
flash_message | boolean Default: false Shows message on screen without user interaction while not saving the message to the inbox. | ||||||||||
truncate_concat | boolean If set to | ||||||||||
max_number_of_message_parts | integer <int32> >= 1 Message will be dispatched only if it is not split to more parts than Max Number of Message Parts | ||||||||||
from_ton | integer <int32> [ 0 .. 6 ] The type of number for the sender number. Use to override the automatic detection. | ||||||||||
from_npi | integer <int32> [ 0 .. 18 ] Number Plan Indicator for the sender number. Use to override the automatic detection. |
Send delivery feedback for a message
When a parameter calledfeedback_enabled
is set in a send batch message call, the SMS API can provide feedback on whether the message was delivered successfully using this send delivery feedback API call. By providing the batch_id
in the path parameter of this operation, users can get delivery feedback for the recipients in the corresponding batch. This is useful in for any user that needs to confirm that their messages are being received. For example, if you're running a marketing campaign, it's essential to have some measure of how successful it was.Making a request
Below are code samples that highlight how to make this API request in multiple languages. Click an appropriate tab to view your preferred language:
- Payload
- Node.js
- C#
- Java
- Python
- curl
- PHP
{- "recipients": [
- "+15551231234",
- "+15551256344"
]
}
For the full schema of the request that corresponds to this API call, see the corresponding entry in the API reference. Alternatively, expand the schema below:
See the schema
Response 202 if successful.