Logo Site EngageLab Mark Colored TransparentDocument
Search

OTP Delivery

This API generates verification codes through the EngageLab platform and delivers them according to the channel strategy specified in the template.

If you want to generate verification codes yourself instead of using the EngageLab platform, you can call the EngageLab OTP Custom Verification Code Delivery API.

Endpoint

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

Authentication

Use HTTP Basic Authentication and add Authorization to the HTTP header:

Authorization: Basic ${base64_auth_string}
              
              Authorization: Basic ${base64_auth_string}

            
This code block in the floating window

The generation algorithm for base64_auth_string is: base64(dev_key:dev_secret)

Request Example

Request Header

POST /v1/messages HTTP/1.1 Content-Type: application/json Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
              
              POST /v1/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", "language": "default", "params": { "key1": "value1", "key2": "value2" } } }
              
              {
  "to": "+6591234567",
  "template": {
    "id": "test-template-1",
    "language": "default",
    "params": {
      "key1": "value1",
      "key2": "value2"
    }
  }
}

            
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 Required Description
to String Required Target recipient: phone number or email address, for example, +6598765432 or support@engagelab.com
template JSON Object Required Template information. See the nested parameters below.
|_ id String Required Template ID
|_ language String Optional Template language. The following languages are supported:
default: Default language
zh_CN: Simplified Chinese
zh_HK: Traditional Chinese
en: English
ja: Japanese
th: Thai
es: Spanish
If not provided, the default value is default (the default language).
|_ params JSON Object Optional Values for custom template variable keys. If you defined custom variables when creating the template, assign values to them here. If not provided, the variable key will be delivered directly, such as {{var}}.

Notes on params

  1. For preset fields in the template, such as from_id, if the param_vars field value is not provided, the template's preset from_id will be used when the message is delivered.
  2. If the param_vars field value is provided, such as param_vars:{"from_id":"12345"}, then the template's from_id will be replaced with 12345 when the message is delivered.
  3. At the same time, custom variable fields in the template content created during template creation are also assigned through param_vars. For example, if the template content is Hi {{name}}, your verify code is {{code}}, then the assignment parameter param_vars:{"name":"Bob"} is required.

Response Parameters

Successful Response

Field Type Required Description
message_id String Required Message ID, which uniquely identifies a message
send_channel String Required Indicates the current delivery channel. Possible values are whatsapp, sms, email, or 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 used to deliver the message to the user. It only indicates the channel currently in use. For example, if the template strategy is configured so that delivery through the WhatsApp channel fails and then automatically retries through the SMS channel, the API response will return the value whatsapp. After a certain period of time, once the delivery failure is detected, the system will send the message through the SMS channel.

Failed Response

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

Field Type Required Description
code int Required Error code. For details, see Error Codes
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; the correct token was not provided
2002 401 Authentication failed; the token has expired or been disabled
2004 403 No permission to call this API
3001 400 Invalid request parameter format. Please check whether the JSON content matches the required parameter format
3002 400 Invalid request parameters. Please check whether the request parameters meet the requirements
3003 400 Invalid request parameters. Related business validation failed. 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, delivery cannot be performed again within the validity period of the verification code
4001 400 The related resource does not exist. For example, a non-existent template is used when sending a template message
5001 400 Sending failed (general/other)
5011 400 Invalid phone number format
5012 400 Target unreachable
5013 400 Number has been added to the blacklist
5014 400 Content does not comply with specifications
5015 400 Message intercepted/rejected
5016 400 Internal sending error
5017 400 No permission to send to mainland China
5018 400 Phone issue (powered off/service suspended)
5019 400 User has unsubscribed
5020 400 Number not registered/invalid number
Icon Solid Transparent White Qiyu
Contact Sales