Send the First SMS
POST Method
SMS is a simple and cost-effective way to communicate with customers. This section details how to send your first outbound SMS using an API request.
Prerequisites
- Before sending the SMS, you must configure the SMS channel in kaleyra.io.
- After you sign up, your account will be on the trial version. You must complete the KYC to access all the features in kaleyra.io.
- Before you get started, Create an API Key. To view the API Key and the SID, see View API Key and SID.
- You must have an approved
SenderIDor a specific number to be used asSenderID.
API Domain and Value
| api_domain | Value |
|---|---|
| IN pod | api.in.kaleyra.io |
| SG Pod | api.ap.kaleyra.io |
| EU Pod | api.eu.kaleyra.io |
| NA pod | api.na.kaleyra.ai |
API request to send the first SMS
To send your first SMS use the <api_domain>/v1/<sid>/sms endpoint with the following request method:
The following is the request format to send the first SMS:
curl --location --request POST 'https://<api_domain>/v1/<SID>/sms' \
--header 'api-key: <api-key>' \
--header 'Content-Type: <content-type>' \
--data '{
"to": "<to>",
"sender": "<sender>",
"type": "<type>",
"unicode": "<unicode>",
"flash": "<flash>",
"time": "<time>",
"prefix": "<prefix>",
"body": "<body>",
"template_id": "<template_id>",
"template_data": {
"example_key0": "<example_key0>",
"example_key1": "<example_key1>",
"example_key2": "<example_key2>"
},
"ref_custom: "['<ref_custom>']",
"callback_profile_id": "<callback_profile_id>"The following is the sample request format to send the first SMS:
curl --location --request POST 'https://api.in.kaleyra.io/v1/HXAP16XXXXXX97IN/sms' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--header 'Content-Type: application/json' \
--data '{
"to": "+91XXXXXXXXXX",
"sender": "KLRHXA",
"type": "MKT",
"unicode": "Auto",
"flash": "1",
"time": "2025-07-11T12:58:00+04:30",
"prefix": "+91",
"body": "Hello, this is your first SMS.",
"template_id": "101XXXXXX012",
"template_data": {
"example_key0": "John",
"example_key1": "23.43",
"example_key2": "USD"
},
"ref_custom: "['John','Doe']",
"callback_profile_id": "IN_09b3dfa7-e05d-4d84-ab2d-6ed654272XXX"URL Parameters and Headers
The following is the list of parameters and headers to send the outgoing message request:
Parameter / Headers | Data Type | Description | Example | Mandatory? |
|---|---|---|---|---|
| String | Account SID (Security Identifier). |
| Yes |
| String | API key generated from kaleyra.io account. |
| Yes |
| String | Indicates the format of the content the API will be processing. | The only allowed value is application/json. | Yes |
| String | Phone number of the end customer you want to send a message to. |
| Yes |
| String | Alphanumeric Sender ID displayed on recipient devices. | KLRHXA | Yes |
Following is the list of attributes to be used in the payload to send the outgoing message:
Parameter | Data Type | Description | Example | Mandatory? |
|---|---|---|---|---|
| String | Route type.
| MKT | Yes |
| String | Determines message encoding. Acceptable values are "AUTO", "0", or "1". If you know it is a unicode message, then use 1. If you know it is not a unicode message, then use 0. If you are not sure about the unicode, then use Auto. | "Auto" | No |
| String | Determines if the message is a flash SMS. Acceptable values are "0" or "1". | "0" | No |
| ISO Date | The time at which the message should be sent. Must be in ISO date format YYYY-MM-DDTHH:MM:SS+HH:MM. | "2025-07-11T12:58:00+04:30" | No |
| String | Country code prefix. If the mobile number does not have a country code and you want to add it as a prefix you have the option to update it here. | "+91" | No |
| String | Body of the SMS. It is required irrespective of whether | "Hello, this is your first SMS." | Yes |
| String | Template ID for pre-registered templates. Required if the body is not provided. template_id must be 12 to 30 digits and exist as a tag. Note: For Indian customers, it is mandatory to use the Template ID and the template must contain a variable parameter, then only the message will get delivered successfully. For example, Users must provide either template_id or body. If a user provides a body in the request then template_id and template_data will be ignored and body will have priority. | ||
| List | It contains an array of max 5 values that will be available in detailed reports and callback associated to the message. The values inside the array can have a maximum of 50 lengths in strings. | ["John","Doe"] | No |
| String | The callback profile ID of the callback profile to be used to send webhook to your system about SMS status updates. For more information related to callback profiles, see callback profiles page. | IN_09b3dfa7-e05d-4d84-ab2d-6ed654272XXX | Yes |
The following table describes the different attributes used for the template_data JSON object, please note that the attribute name is not static but must be the same name as the name given to the placeholders (also known as dynamic variables) used in the template:
| Parameter / Headers | Data Type | Description | Example | Mandatory? |
|---|---|---|---|---|
example_key0 | String | The template_data attribute will be validated for string size (maximum of 30 characters per value). | John | No |
Note:
The following are the validations for template-based SMS API's:
- The template_data attribute will be validated for string size (maximum of 30 characters per value).
- A check is performed to ensure all keys in the template are included in template_data parameter.
- Users must provide either template_id or body. If a user provides a body in the request template_id and template_data will be ignored and we will give priority to the body.
Response Format
This section provides you the success and failure JSON response formats for different scenarios.
Success Response
The following success response is received when the JSON script has the correct syntax:
{
"id": "ee8aXXXX-XXXX-XXXX-XXXX-9b717XXXX30d",
"sender": "KLRHXA",
"type": "DEFAULT",
"body": "Hello, this is your first SMS.",
"createdDateTime": "2024-07-13T12:58:00+04:30",
"totalCount": 1,
"data": [
{
"message_id": "ee8aXXXX-XXXX-XXXX-XXXX-9b717XXXX30d:1",
"recipient": "+91XXXXXXXXXX"
}
],
"dlrurl": null,
"error": {}
}Failure Responses
The following failure responses are received when the JSON script has an incorrect syntax:
{
"code": "E401",
"message": "SMS length is exceeding 4000 characters.",
"error": {
"body": "SMS length is exceeding 4000 characters."
}
}Two-way SMS for Customer Engagement
Kaleyra's Two-Way SMS API offers an easy and efficient way to communicate with your customers. It allows you to instantly send and receive messages through your choice of long or short codes.
If you have purchased a two-way SMS number, you must pass the same number as a Sender ID in the above API call to initiate a two-way conversation with your customers.
Note:The two-way SMS for customer engagement feature is available based on region. For example, it is available for customers registered in the EU and the SG regions. This feature is not available for customers registered in the IN region.
Sample Request Format
curl --location --request POST "https://api.in.kaleyra.io/v1/HXAP16XXXXXX97IN/sms" \
--header "api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3" \
--header "Content-Type: application/json" \
--data-urlencode "to= +91XXXXXXXXXX" \
--data-urlencode 'body= Hello, this is your first SMS.' \
--date-urlencode 'template_id: 101XXXXXX012' \
--data-urlencode 'sender= +917xxxxxx834' \
--data-urlencode 'type= MKT' \
--data-urlencode "ref_custom= ['John','Doe']"\
--data-urlencode "callback_profile_id= IN_09b3dfa7-e05d-4d84-ab2d-6ed654272XXX"
Note:For Two-way SMS, the sender variable must be Numeric. For example, +917xxxxxx834.
SMS Error Codes, SMS Status and Status Trace Codes
Refer to the following links for Error Codes, Status and Status Trace Codes:
- For information related to SMS error codes, see SMS Error Codes.
- For information related to SMS status and status trace codes, see SMS Status and Status Trace Codes.
Updated 6 days ago
