Logo Site EngageLab Mark Colored TransparentDocument
Search

Custom OTP Code Delivery

If you want to generate verification codes yourself instead of having them generated by the EngageLab platform, you can call this API.

This API is specifically used to send pre-generated verification codes and does not generate verification codes on its own. After sending a verification code, there is no need to call a verification API to validate it.

If you want the EngageLab platform to generate verification codes, you can call the EngageLab OTP Verification Code Delivery API.

Endpoint

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

Authentication

Use HTTP Basic Authentication by adding 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 above is: base64(dev_key:dev_secret)

Request Example

Request Header

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

            
This code block in the floating window

Request Body

{ "to": "+8618701235678", "code": "398210", "template": { "id": "test-template-1", "language": "default", "params": { "key1": "value1", "key2": "value2" } } }
              
              {
  "to": "+8618701235678",
  "code": "398210",
  "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 Delivery target: a phone number or email address, such as +8613800138000 or support@engagelab.com
code String Required The custom verification code to send
template JSON Object Required Template information. See the second-level 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 their values here. If not provided, the variable key will be sent directly, such as {{var}}.

Description of params

  1. For preset template fields such as from_id, if the param_vars field value is not provided, the preset from_id in the template will be used when the message is sent.
  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 sent.
  3. Custom variable fields in the template content that were created during template creation are also assigned values 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: whatsapp/sms/email/voice
{ "message_id": "1725407449772531712", "send_channel": "sms" }
              
              {
  "message_id": "1725407449772531712",
  "send_channel": "sms"
}

            
This code block in the floating window

Please note that the returned send_channel value does not represent the final channel used to deliver the message to the user; it only represents the channel currently in use. For example, if the template strategy is configured so that delivery through the WhatsApp channel will automatically retry through the SMS channel if it fails, then the API response will return the value whatsapp. After a certain period of time, if a delivery failure is detected, the system will send 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 has 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 made again within the verification code validity period.
4001 400 The 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 phone number format
5012 400 Target unreachable
5013 400 Number has been blacklisted
5014 400 Content does not comply with specifications
5015 400 Message intercepted/rejected
5016 400 Internal sending error
5017 400 No sending permission for mainland China
5018 400 Phone malfunction (powered off/service suspended)
5019 400 User has unsubscribed
5020 400 Number not registered/invalid number
Icon Solid Transparent White Qiyu
Contact Sales