REST API 概述

最新更新:2023-03-07

基本约束

  • API 被设计为符合 HTTP、 REST 规范。例如:查询请求使用 Get 方法,提交请求使用 POST 方法。如果一个请求不是相应的 HTTP 方法,将返回错误。
  • 如无特殊说明,调用参数值应转码为:UTF-8, URL 编码

数据中心及Base URL

数据中心 Base URL
新加坡 https://webpush.api.engagelab.cc/v4
中国香港 https://webpush-hk.api.engagelab.cc/v4

当使用REST API时,需要将选定的base URL与具体API的路径结合起来获得完整的调用地址。

{base URL}/{API路径}
          {base URL}/{API路径}

        
此代码块在浮窗中显示

其中,{base URL}是选定的数据中心的base URL,{API路径}是具体API的路径,如 v4/devices/{registration_id}

示例:

  • 假设选择了新加坡数据中心,其base URL为 https://webpush.api.engagelab.cc
  • 如果要删除特定设备的注册信息,API路径是 v4/devices/{registration_id},则完整的API调用地址为:
https://webpush.api.engagelab.cc/v4/devices/{registration_id}
          https://webpush.api.engagelab.cc/v4/devices/{registration_id}

        
此代码块在浮窗中显示

其中, {registration_id} 是具体设备的注册ID。

通过这种方法,您可以构建出用于访问不同数据中心的完整的API调用地址。

鉴权方式

Engagelab REST API 采用 HTTP 基本认证 的验证方式。 基本做法为,HTTP Header(头)里加 Authorization:

Authorization: Basic base64_auth_string
          Authorization: Basic base64_auth_string

        
此代码块在浮窗中显示

其中 base64_auth_String 的生成算法为:base64(appKey:masterSecret) 即,对 appKey 加上冒号,加上 masterSecret 拼装起来的字符串,再做 base64 转换。
进入【应用设置】-【应用信息】页面获取 appKey 和 masterSecret 参数。 image.png

鉴权举例

你的 appKey 是 "c96f42e0d2e662e45d035ab1", masterSecret 是 "df4d59e84eac2f9d53b36f12",则调用 Push API v4 时,使用 curl 命令调用如下:

curl --insecure -X POST -v https://webpush.api.engagelab.cc/v4/push -H "Content-Type: application/json" -u "c96f42e0d2e662e45d035ab1:df4d59e84eac2f9d53b36f12" -d '{ "from": "push", "to": "all", "body": { "platform": "web", "notification": { "alert": "Hi,MTPush !", "web": { "alert": "Hi,MTPush !", "title": "web_push", "url": "http://www.google.com", "extras": { "web-key1": "web-value1" } } } }, "request_id": "12345678", "custom_args": "business info" }'
           curl --insecure -X POST -v https://webpush.api.engagelab.cc/v4/push 
-H "Content-Type: application/json" 
-u "c96f42e0d2e662e45d035ab1:df4d59e84eac2f9d53b36f12" 
-d '{
    "from": "push",
    "to": "all",
    "body": {
        "platform": "web",
        "notification": {
            "alert": "Hi,MTPush !",
            "web": {
                "alert": "Hi,MTPush !",
                "title": "web_push",
                "url": "http://www.google.com",
                "extras": {
                    "web-key1": "web-value1"
                }
            }
        }
    },
    "request_id": "12345678",
    "custom_args": "business info"
}'

        
此代码块在浮窗中显示

HTTP 请求发出的请求是:

> POST /v4/push HTTP/1.1 > Authorization: Basic Yzk2ZjQyZTBkMmU2NjJlNDVkMDM1YWIxOmRmNGQ1OWU4NGVhYzJmOWQ1M2IzNmYxMg==
          > POST /v4/push HTTP/1.1
> Authorization: Basic Yzk2ZjQyZTBkMmU2NjJlNDVkMDM1YWIxOmRmNGQ1OWU4NGVhYzJmOWQ1M2IzNmYxMg==

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