Create SMS Template API

The Create SMS Template  API can be used to create an SMS template in MoEngage. This API helps you upload templates created outside the MoEngage ecosystem to MoEngage and use them for campaign creation.

API Endpoint

API Endpoint
POST https://api-0X.moengage.com/v1.0/custom-templates/sms

Each customer is hosted on a different data center; you can find your data center number (value of X) by checking the data center and API endpoint mapping page.

Authentication

The API request will be authenticated through Basic Authentication. Basic Authentication sends a Base64-encoded string containing your username and password with every API request. It encodes a 'username:password' string in Base64 and appends the encoded string with 'Basic '. This string is included in the authorization header as shown below:

{"Authorization":"Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U="}

The username and password details can be obtained from the MoEngage Dashboard. We've revamped the settings UI in the Dashboard. If you're using the API for the first time, follow these steps for the revamped and old UIs:

Revamped UI

  1. Navigate to Settings -> Account -> APIs.
  2. Click the Copy icon in the Campaign report/Business events/Custom templates tile in the API Keys section to copy the API Key.
  3. Use the App ID as the username and the Push API Key as the password to generate the authentication header.

Old UI

  1. Navigate to Settings -> APIs -> TRANSACTION PUSH/REPORT Settings.
  2. Click on the Click here to show APP Secret link to view the API SECRET.
  3. Use the APP ID as the username and the API SECRET as the password to generate the authentication header.

Request Headers

Key Required Sample Values Description

Content-Type

Required

{"Content-Type": "application/json"}

Set the Content-Type header to application/json.

Authorization

Required

{"Authorization": "Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U=="}

This authentication parameter, used for access control, must be passed along with the request. To generate the authentication header, refer to Authentication.

Request Body

Key Required Values Description
basic_details Required JSON Object

This field contains the basic details of the SMS template.

Structure of basic_details Object:

"basic_details": {
    "message": "Sample Template message"}

The basic_details object contains the following fields:

  • message: This field contains the message template. It is a String and is mandatory.
meta_info Required JSON Object

This field contains information about the template being created, such as the name, version, and id of the template and the creator's details.

Structure of meta_info:

"meta_info": {
    "created_by": "<creator details>",
    "template_id": "<template id>",
    "template_name": "<template name>",
    "template_version": "<template version>"
}

The meta_info object contains the following fields:

  • created_by - This field contains details about who created the template. This value should be provided by you.
  • template_id - This field contains the ID for the template and is unique. This ID should be provided by you.
  • template_name - This field contains the name of the template. This value should be provided by you and would be used for identifying the template.
  • template_version - This field contains the version of the template. This value should be provided by you and would be used for tracking the template's version.

Note: All the fields in the meta_info object are String fields and are mandatory.

Response

Key Data Type Description
external_template_id String This field contains the unique template id corresponding to a successful template creation request.
error JSON Object

This field contains the reason for the request's failure.

Structure:

 "error": {

    "code": "<error_code>", 

    "message": "<error_message>",

     "details": [],

    "request_id": "<unique identifier for the request>

}

The error object contains the following fields:

  • code - This field contains the error code that provides a brief explanation of the error and is a String. For example, 400 - Bad Request, 401- Authentication required, and so on. This field is present in the response only in the case of errors.
  • message - This field describes why the request has failed and is a String. For example, in the case of a duplicate request (400- Bad Request), the following message will be present: 'Duplicate - template_id and template_version'.
  • details - This is a List of the error details objects. Each object contains the following information:

           { 

             "code": "<Descriptive Error Code>",

             "target": "<Denotes the field causing the issue or a brief description of the error message in some cases >",

              "message": "<Descriptive Error Message>"

            }

  • request_id -  This field contains the unique id pertaining to the request.

For example, in the case of a 400 request where the request is trying to create a template that is already present, the following error object is returned.

{
"error": {
"code": "400 Bad Request",
"message": "Duplicate - template_id and template_version",
"details": [
{
"code": "InvalidValue",
"target": "Duplicate - template_id and template_version",
"message": "template_id:<template_id> template_version:<template_version> is already present."
}
],
"request_id": "cLCcgLQj"
}

Response Codes

Status Code Request State Description

200

Success

This response is returned when the request is processed successfully. 

400

Bad Request

This response is returned when the required parameters are missing from the request or when the provided parameters are invalid, or when a template already exists with the same version, name, or id.

401

Authorization Failure

This response is returned when the authorization parameters are missing in the HTTP Auth Header.

403

Unauthorized Access

This response is returned when the authorization fails due to incorrect values for the APP KEY/ HTTP Auth Header.

415

Unsupported File Type

This response is returned when the header Content-Type is not provided/is not supported.

429

Rate Limit Breach

This response is returned when the number of requests per minute has exceeded the rate limit or the number of templates has exceeded the allowed quota per channel.

5xx

Internal Server Error

This response is returned when the system runs into an unexpected error.

Rate Limit

The rate limit is 100 RPM. You can upload a maximum of 100 templates per channel.

Sample cURL Request

cURL
curl --location 'https://api-0X.moengage.com/v1.0/custom-templates/sms/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic e3tBUFBfSUR9fTp7e0FQSV9TRUNSRVR9fQ==' \
--data '{
  "basic_details": {
    "message": "Sample SMS Template message"
  },
  "meta_info": {
    "created_by": "John Doe",
    "template_id": "BasicTemplate1",
    "template_name": "BasicMessageTemplate",
    "template_version": "1"
  }
}'

Sample Response

200 400 401 403 415 429 5xx
Sample Response for a successful request
{
  "external_template_id": "d05a44f0-a7cf-471a-bcb6-63054800a367"
}

Postman Collections

We have made it easy for you to test the APIs. Click here to view it in Postman.

FAQs

  • Can I create multiple templates with the same name?
    Yes, you can create multiple templates with the same name, provided they have different versions.

Previous

Next

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?