REST API Overview

อัพเดทล่าสุด :2024-07-10

Basic

  • API is designed to comply with HTTP and REST specifications. For example, the Get method is used for query requests and the POST method is used for submission requests. If a request is not a corresponding HTTP method, an error is returned
  • If there is no special description, the value of the call parameter should be transcoded as UTF-8, URL Coding

Data Centers and Base URL

Data Center Base URL
Singapore https://webpush.api.engagelab.cc/v4
Hong Kong https://webpush-hk.api.engagelab.cc/v4

When using REST API, it's necessary to combine the chosen base URL with the specific API path to obtain the complete endpoint.

{base URL}/{API path}
          {base URL}/{API path}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Here, {base URL} represents the selected data center's base URL, and {API path} denotes the specific API endpoint path, such as v4/devices/{registration_id}.

Example:

  • Suppose the Singapore data center is chosen with a base URL of https://webpush.api.engagelab.cc.
  • If the goal is to delete registration information for a specific device, and the API path is v4/devices/{registration_id}, then the complete API endpoint would be:
https://webpush.api.engagelab.cc/v4/devices/{registration_id}
          https://webpush.api.engagelab.cc/v4/devices/{registration_id}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Here, {registration_id} represents the specific device's registration ID.

Using this approach, you can construct complete API endpoint URLs for accessing different data centers.

Authentication Method

Engagelab REST API uses HTTP basic authentication The basic method is to add HTTP Header Authorization (Header)::

Authorization: Basic base64_auth_string
          Authorization: Basic base64_auth_string

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The base64_auth_String generation algorithm isbase64(appKey:masterSecret)
That is, add a colon to the appKey, add the masterSecret assembled string, and then perform base64 conversion
Go to the application settings-application information page to obtain the appKey and masterSecret parameters
image.png

Authentication Example

If your appKey is "c96f42e0d2e662e45d035ab1", and masterSecret is "df4d59e84eac2f9d53b36f12",when you call Push API v4, use the curl Command to call the following:

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"}'

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The HTTP request is:

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย
在文档中心打开
Contact Sales