Logo Site EngageLab Mark Colored TransparentDocument
Search

Custom Send Message

If you have created custom template content on the OTP platform, you can call this interface to send custom message content.

Request URL

POST https://otp.api.engagelab.cc/v1/custom-messages

Authentication

Please refer to Authentication to learn how to perform API authentication.

Request Format

Request Header

POST /v1/custom-messages HTTP/1.1 Content-Type: application/json Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
              
              POST /v1/custom-messages  HTTP/1.1  
Content-Type: application/json  
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0

            
This code block in the floating window

Request Body

{ "to": "+6591234567", "template":{ "id":"test-template-1", "params": { "code": "codevalue", "var1":"value1" } } }
              
              {
    "to": "+6591234567", 
    "template":{
      "id":"test-template-1",
      "params": {
        "code": "codevalue",
        "var1":"value1"
        }
    }
}

            
This code block in the floating window

Request Parameters

A request object is expressed in JSON format, so the request header must include Content-Type: application/json.

Parameter Type Option Description
to String Required Sending target, mobile number or email address, +6598765432, support@engagelab.com
template JSON Object Required Template information, see secondary parameters below
|_ id String Required Template ID
|_ params JSON Object Optional Template parameters
_ |_ code String Optional When the template type is verification code, this field is required.
_ |_ var String Optional Values for custom template variable keys. If you customized variables when creating the template, pass their values here. If not passed, they will be sent directly as variable keys, such as {{var1}}

Notes on params

  1. For template preset variables such as {{brand_name}}, {{ttl}}, {{pwa_url}}, etc., there is no need to pass them; the system will automatically replace them with the content specified when the template was created;
  2. If the template type is a verification code, the {{code}} variable must be passed, otherwise an error will be reported;
  3. At the same time, for custom variable fields in the template content when creating the template, they are also assigned values through params. For example, if the template content is Hi {{name}}, your verify code is {{code}}, you need to assign the parameter params:{"name":"Bob"}.
  4. Email Channel Special Variables: For the Email channel, you can dynamically override the email subject (subject), sender name (from_name), sender email (from_mail), etc., through params. For detailed advanced usage, please refer to Create Template - Email Template Variables Advanced Usage.

Request Example

1. Send Custom Verification Code:

{ "to": "+6591234567", "template":{ "id":"code-template", "params": { "code": "123456" } } }
              
              {
    "to": "+6591234567", 
    "template":{
      "id":"code-template",
      "params": {
        "code": "123456"        
        }
    }
}

            
This code block in the floating window

2. Send Custom Notification Content:

{ "to": "+6591234567", "template": { "id": "notification-template", "params": { "order": "123456" } } }
              
              {
    "to": "+6591234567",
    "template": {
        "id": "notification-template",
        "params": {
            "order": "123456"
        }
    }
}

            
This code block in the floating window

3. Send Custom Marketing Content:

{ "to": ["+6591234567"], "template": { "id": "marketing-template", "params": { "name": "EngageLab", "promotion": "30%" } } }
              
              {
    "to": ["+6591234567"],
    "template": {
        "id": "marketing-template",
        "params": {
            "name": "EngageLab",
            "promotion": "30%"
        }
    }
}

            
This code block in the floating window

Response Parameters

Success Response

Field Type Option Description
message_id String Required Message ID, uniquely identifies a message
send_channel String Required Indicates the current sending channel, values are whatsapp/sms/email/voice
{ "message_id": "1725407449772531712", "send_channel": "sms" }
              
              {
    "message_id": "1725407449772531712",
    "send_channel": "sms"
}

            
This code block in the floating window

Note that the returned send_channel value does not represent the final channel delivered to the user, but only represents the channel used at this stage; for example, if the strategy configured in the template specifies that the WhatsApp channel fails to deliver and then automatically falls back to the SMS channel, the interface will return the whatsapp value. After sensing the delivery failure after a certain period of time, the system will use the SMS channel to send.

Failure Response

The HTTP status code is 4xx or 5xx, and the response body contains the following fields:

Field Type Option Description
code int Required Error code, see error code description for details
message String Required Error details
{ "code": 5001, "message": "sms send fail" }
              
              {
    "code": 5001,
    "message": "sms send fail"
}

            
This code block in the floating window

Error Codes

Error Code HTTP Code Description
1000 500 Internal error
2001 401 Authentication failed, incorrect token carried
2002 401 Authentication failed, token has expired or been disabled
2004 403 No permission to call this API
3001 400 Invalid request parameter format, please check if the JSON content conforms to the parameter format
3002 400 Incorrect request parameters, please check if the request parameters meet the requirements
3003 400 Incorrect request parameters, related business verification failed, please refer to the error description in the message field for details
3004 400 Frequency limit exceeded, for the same template and the same target user, it cannot be sent again within the validity period of the verification code
4001 400 Related resource does not exist, such as using a non-existent template when sending a template message
5001 400 Sending failed (general/other)
5011 400 Invalid mobile number format
5012 400 Target unreachable
5013 400 Number is blacklisted
5014 400 Content does not meet specifications
5015 400 Message intercepted/rejected
5016 400 Internal sending error
5017 400 No sending permission for China region
5018 400 Mobile phone failure (powered off/out of service)
5019 400 User has unsubscribed
5020 400 Number unregistered/empty number
Icon Solid Transparent White Qiyu
Contact Sales