HMS Corepush serviceDevelopers are supported to use the HTTPS protocol to access the Push server. Postman is an interface testing tool that simulates various HTTP requests initiated by users, sends the request data to the server, and obtains the corresponding response results. Postman can simulate requests from the developer server to apply for an Access Token and call interfaces such as authentication.
Therefore, many developers choose to use Postman to test the push interface when testing the effect of pushing on the client side or locating push problems. For example, when a developer wants to use the interface to push test messages but it is inconvenient to use the application’s official server to push directly, they can use Postman to simulate the server’s push request. Or the server interface cannot be debugged, and you are not sure whether there is a problem with the parameters, you can use postman to verify whether the request is successful. This article will introduce the specific steps of using Postman to call the push interface of HMS Core.
1. Download and install Postman
download link:https://www.postman.com/downl…, click Download, download the corresponding version, and then install it. This article uses version v7.36.1.
If the network uses a proxy, you need to configure a proxy for Postman (if the network does not have a proxy, please ignore it):
- Open the File menu, click the Settings menu, and the settings interface will pop up.
- Select Proxy in the settings interface to configure your network proxy.
2. Call the authentication interface to obtain the Access Token.
- Create a new Tab in Postman, enter the interface address, and select the POST method:
- Select body, check “x-www-form-urlencoded”, and enter the parameter name and corresponding value in the list below.
The three parameters are described as follows:
grant_type – fixed value “client_credentials”.
client_id – For AppGallery Connect apps, the value of the OAuth 2.0 client ID (credentials) in the appClient ID。
client_secret – For AppGallery Connect apps, the value of the OAuth 2.0 client ID (credential) in the appClient Secret。
Click send, you can call the interface to return access_token, as shown in the following figure:
- Save the debugging configuration, press ctrl+s, enter the name “Get Token”, and create a new directory “push” to save.
3. Call the message push interface to send the Push message
- Create a new Tab in Postman, enter the interface address (replace [appid] with the actual appid), and select the POST method:
- Select Authorization, select “Bearer Token” for TYPE, and then enter the access_token obtained in the second step in the Token input box, as shown in the following figure:
- Select Body, select “raw”, select “JSON” from the drop-down box, then copy the message content in the input box below, click send, and you can send the message, as shown below:
- Save the debugging configuration, press ctrl+s, enter the name “Send Message”, and save it in the directory “push”.
Fourth, use Postman to generate commands for other common tools/languages
Using Postman’s existing successful debugging interface, commands for other tools can be automatically generated, such as commonly used cURL, Nodejs, Python, Ruby, etc., which can be copied and used directly.
How to get it: On the right side of the window, click Code, the command page will pop up, and you can select the command in the language you want.
Finally, the example file exported using Postman is attached, and developers in need can directly import the test.
Learn more details>>
Follow us to know the latest technical information of HMS Core for the first time~