Group Push API
功能說明
此 API 用於建立應用程式群組推播,只需呼叫一次,即可對該群組下的所有應用程式進行訊息推播。
- 目前暫不支援 option 中的 override_msg_id 屬性。
- 群組推播僅在控制台推播時支援設定排程任務,不支援呼叫 Schedule API 來設定排程任務。
呼叫驗證
在 HTTP Header 中加入一個欄位(Key/Value 配對):
Authorization: Basic ${base64_auth_string}
Authorization: Basic ${base64_auth_string}
此代碼塊在浮窗中顯示
上述 base64_auth_string 的產生演算法為:base64(username:password)
Header 名稱為 "Authorization",值為經過 base64 轉換的 "username:password" 配對(中間有一個冒號)。
在群組推播 API 的情境中,username 為加上「group-」前綴的 GroupKey,password 為 Group Master Secret。這兩者可在控制台【群組管理】→【編輯】中查看。

呼叫位址
POST v4/grouppush
POST v4/grouppush
此代碼塊在浮窗中顯示
請求範例
curl --insecure -X POST -v https://pushapi-sgp.engagelab.com/v4/grouppush -H "Content-Type: application/json" -u "c96f42e0d2e662e45d035ab1:df4d59e84eac2f9d53b36f12" -d
'{
"from": "push",
"to": "all",
"body": {
"platform": "all",
"notification": {
"android": {
"alert": "Hi, Push!",
"title": "Send to Android",
"builder_id": 1,
"extras": {
"newsid": 321
}
},
"ios": {
"alert": "Hi, MTPush!",
"sound": "default",
"badge": "+1",
"extras": {
"newsid": 321
}
},
"hmos":{
"alert": "Hi, MTPush!",
"title": "",
"category": "",
"intent": {"url": ""},
"badge_add_num": 1,
"test_message": true,
"receipt_id":"",
"extras":{},
"style":0,
"inbox_content":[],
"push_type":0,
"extra_data":"",
"display_foreground":""
}
}
},
"options": {
"time_to_live": 60,
"apns_production": false
}
},
"request_id": "12345678",
"custom_args": "business info"
}'
> POST /v4/grouppush HTTP/1.1
> Authorization: Basic Yzk2ZjQyZTBkMmU2NjJlNDVkMDM1YWIxOmRmNGQ1OWU4NGVhYzJmOWQ1M2IzNmYxMg==
curl --insecure -X POST -v https://pushapi-sgp.engagelab.com/v4/grouppush -H "Content-Type: application/json" -u "c96f42e0d2e662e45d035ab1:df4d59e84eac2f9d53b36f12" -d
'{
"from": "push",
"to": "all",
"body": {
"platform": "all",
"notification": {
"android": {
"alert": "Hi, Push!",
"title": "Send to Android",
"builder_id": 1,
"extras": {
"newsid": 321
}
},
"ios": {
"alert": "Hi, MTPush!",
"sound": "default",
"badge": "+1",
"extras": {
"newsid": 321
}
},
"hmos":{
"alert": "Hi, MTPush!",
"title": "",
"category": "",
"intent": {"url": ""},
"badge_add_num": 1,
"test_message": true,
"receipt_id":"",
"extras":{},
"style":0,
"inbox_content":[],
"push_type":0,
"extra_data":"",
"display_foreground":""
}
}
},
"options": {
"time_to_live": 60,
"apns_production": false
}
},
"request_id": "12345678",
"custom_args": "business info"
}'
> POST /v4/grouppush HTTP/1.1
> Authorization: Basic Yzk2ZjQyZTBkMmU2NjJlNDVkMDM1YWIxOmRmNGQ1OWU4NGVhYzJmOWQ1M2IzNmYxMg==
此代碼塊在浮窗中顯示
請求參數
請求參數請參考 建立推播 API。
回傳範例
成功回應
{
"0c3de43c6a6b68c9f4261b06": {"request_id":"12345678","msg_id":"2460001"},
"35c424abde12f475566ca8af": {"request_id":"12345678","msg_id":"2460001"},
"8f02a4fa717a6235734d92de": {"request_id":"12345678","msg_id":"2460001"},
"group_msgid": "cbou2uum98lps87rtic0"
}
{
"0c3de43c6a6b68c9f4261b06": {"request_id":"12345678","msg_id":"2460001"},
"35c424abde12f475566ca8af": {"request_id":"12345678","msg_id":"2460001"},
"8f02a4fa717a6235734d92de": {"request_id":"12345678","msg_id":"2460001"},
"group_msgid": "cbou2uum98lps87rtic0"
}
此代碼塊在浮窗中顯示
失敗回應
{
"error":{
"code":21037,
"message":"group_key is not a 24 size string or does not exist"
}
}
{
"error":{
"code":21037,
"message":"group_key is not a 24 size string or does not exist"
}
}
此代碼塊在浮窗中顯示
錯誤碼
詳情請參考 「建立推播 API - 呼叫回傳」。
