發送相關

最新更新: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"
}

        
此代碼塊在浮窗中顯示
在文档中心打开