发送相关

最新更新:2023-04-10

Send

发送一个短信模板给一个或多个用户

URL

https://sms.api.engagelab.cc/v1/send
          https://sms.api.engagelab.cc/v1/send

        
此代码块在浮窗中显示

HTTP请求方式

POST
          POST    

        
此代码块在浮窗中显示

Content-Type

Content-Type: application/json;charset=utf-8
          Content-Type: application/json;charset=utf-8

        
此代码块在浮窗中显示

请求Headers

Header 类型 必须 说明
Authorization String true Basic base64(sms_user:sms_key)

参数说明

参数 类型 必须 说明
from string 发送方名称,最大支持3-11个字符,且只能是英文和数字,默认为空。显示以实际效果为准
to array 手机号列表,列表最大为1000个
body object 短信内容设置
template_id int 模板ID
msg_type int 业务类型,2代表国际短信,默认为2
label_id int 短信标签
vars object 变量。最大支持1MB。
custom_args object 客户自定义的可选字段,最大支持1KB。
request_id string 本次发送请求ID;最大支持128字符。

注意:

  1. vars用于邮件内容的变量替换,格式为json对象,格式为{"varname":"value1"},其中varname为邮件内容变量。
  2. 短信内容为:欢迎使用%sp%短信服务。对应vars传值:{"sp":"engagelab"} 短信内容替换:欢迎使用engagelab短信服务。
  3. vars中的每一个value长度默认不能超过16个字符,格式为字符串,,变量中不能含有 HTTP 链接(特殊需求请联系客服)。
  4. 系统会用vars中的参数替换短信模板中的变量,所有手机号收到的是替换后的同一个内容。
  5. customer_args 作为客户自定义内容,在后续的SMSHook数据中,会回传给客户 。
  6. request_id 为防止重复提交,有效期1小时。若1小时内重复提交,将返回上次请求结果。

请求示例

curl -X POST "https://sms.api.engagelab.cc/v1/send" --header "Authorization: Basic <<YOUR_SMS_KEY_HERE>>" --header "Content-Type: application/json" --data '{ "from": "xxxx", "to": ["+12673800456", "+12673800455"], "request_id":"123" , "body":{ "template_id": 2336, "label_id": 231, "vars": { 'week':'Tuesday' } } }'
          curl -X POST "https://sms.api.engagelab.cc/v1/send" 
--header "Authorization: Basic <<YOUR_SMS_KEY_HERE>>" 
--header "Content-Type: application/json" 
--data '{
    "from": "xxxx",
    "to": ["+12673800456", "+12673800455"],  
     "request_id":"123" ,
    "body":{
        "template_id": 2336,
        "label_id": 231,
        "vars": {
        'week':'Tuesday'
        }
    }
}'  

        
此代码块在浮窗中显示

响应说明

参数 说明
success_count 发送成功数量
sms_ids 发送成功的短信id列表
failed_count 发送失败数量
failed_items 发送失败的手机列表及失败原因
phone 手机号
message 失败原因
request_id 客户自定义的可选字段
custom_args 本次发送请求ID

响应示例

Response-success

HTTP Status: 200

//成功的返回结果示例 { "sms_ids": ["1458113381893_15_3_11_1ainnq$+12673800456", "1458113381893_15_3_11_1ainnq$+12673800456"] "request_id":"123" } // 部分成功的返回结果示例 { "code": 41031, "success_count": 1, "sms_ids": ["1458113381893_15_3_11_1ainnq$+12673800456"], "request_id":"123" , "failed_count": 1, "failed_items": [{ "phone":"1233", "message":"Invalid phone number format" } ], "message": "partial success" }
          //成功的返回结果示例
{ 
  "sms_ids": ["1458113381893_15_3_11_1ainnq$+12673800456", "1458113381893_15_3_11_1ainnq$+12673800456"]   
  "request_id":"123" 
}

// 部分成功的返回结果示例
{
      "code": 41031,
      "success_count": 1,
      "sms_ids": ["1458113381893_15_3_11_1ainnq$+12673800456"],
      "request_id":"123" ,
      "failed_count": 1,
      "failed_items": [{
          "phone":"1233",
          "message":"Invalid phone number format"
          }
       ],
       "message": "partial success"
}

        
此代码块在浮窗中显示

Response-error

HTTP Status :401

{ "code": 30000, "message": "Unauthorized." }
          {
    "code": 30000,
    "message": "Unauthorized."
}

        
此代码块在浮窗中显示

Response-error

HTTP Status :400

{ "code": 32002, "message": "Invalid phone number format" }
          
{
    "code": 32002,
    "message": "Invalid phone number format"
}

        
此代码块在浮窗中显示
在文档中心打开