[Huawei Developers] Freemind R:
[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401042720.87646494794073560477531566646413:50510426063352:2800:F6FEAA93D24FE516EB02C2DAB74B60611CF9729763CEEE3CCFDF3740D92E0BC2.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401042720.87646494794073560477531566646413:50510426063352:2800:F6FEAA93D24FE516EB02C2DAB74B60611CF9729763CEEE3CCFDF3740D92E0BC2.png[/IMG]

Before we start learning about today’s topic, I strongly recommend you to go through my previous article i.e. How to know more about the client with Huawei Push Kit. It will help you to have a clear picture of HMS Push Kit.

Let’s Begin

Today in this article we are going to see how to send notification to devices from server using HMS Push Kit. To mimic the server part I am using POSTMAN. It is a great tool when trying to dissect RESTful APIs made by others or test ones you have made yourself. It offers a sleek user interface with which to make HTML requests, without the hassle of writing a bunch of code just to test an API's functionality.

1) The push token which we have received from client side (Mobile or web), we will store them in server side database.

2) Why do we need push token?

Earlier in my article we send a notification from Huawei developer console using push token. We will do the same here using POSTMAN.

3) We need our app Client Id and Client Secret to proceed further.

Actually here our client Id and client secret is our app id and app secret which we will be able to find in our AGC App information section.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401043156.54499044135426729431908821667604:50510426063352:2800:2C358C57BD1948600883B41FC29B5089EE2381D6BF26548367693088D0E81728.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401043156.54499044135426729431908821667604:50510426063352:2800:2C358C57BD1948600883B41FC29B5089EE2381D6BF26548367693088D0E81728.png[/IMG]

4) We need to call two URL to serve the purpose. For both URL, protocol is POST.

https://oauth-login.cloud.huawei.com/oauth2/v3/token

The above URL will help us to get App-Level Access Token. The Access token as we know expires every 60 minutes. So, we need to call them every 60 minutes if it get expires. This token is required to send notification.

i) POSTMAN Header Parameter

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401043603.11809827300046974450949777910785:50510426063352:2800:1D1BE51BF29B81925FBDB0A76008B0ECB288ADB1DF17D190782BA9801A2735F7.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401043603.11809827300046974450949777910785:50510426063352:2800:1D1BE51BF29B81925FBDB0A76008B0ECB288ADB1DF17D190782BA9801A2735F7.png[/IMG]

In the header parameter of POSTMAN, we need three Key-Value pair.

ii) POSTMAN Body Parameter

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401044800.32797995115819807209482367748913:50510426063352:2800:952A6D2A0CDC4D3D51BA42BA5A4E7CEAF4243713DC8AED7497731C4E273165E2.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401044800.32797995115819807209482367748913:50510426063352:2800:952A6D2A0CDC4D3D51BA42BA5A4E7CEAF4243713DC8AED7497731C4E273165E2.png[/IMG]

In the body parameter of POSTMAN, we need three Key-Value pair.

iii) The Result

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401045115.30769216524084580934274238621925:50510426074858:2800:AE27FD76F98FEB91CFA8BEE8537B84CEECBCBBBCBF471674831A3BAAD0E91494.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401045115.30769216524084580934274238621925:50510426074858:2800:AE27FD76F98FEB91CFA8BEE8537B84CEECBCBBBCBF471674831A3BAAD0E91494.png[/IMG]

After putting the header and the body parameters, we click the send button to get the access token as a result.

https://push-api.cloud.huawei.com/v1/[App ID]/messages:send

After receiving the App-Level Access token, we will use the token in HTTP header parameter to send notification. In the above URL we will replace App ID with our app id which we will obtained from AGC.

i) POSTMAN Params and Header Parameter

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401045941.59128954533033313219912103158916:50510426063352:2800:501B1EE986822591DE32A6E8944A430B70B0BCA0E7C4FC5CEBE11ADA1AA5806E.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401045941.59128954533033313219912103158916:50510426063352:2800:501B1EE986822591DE32A6E8944A430B70B0BCA0E7C4FC5CEBE11ADA1AA5806E.png[/IMG]

In the POSTMAN you will find a button name as Params. Click the button to put the Key and Value of Params.

In the Authorization value, a space character must be added between Bearer and the value of App-Level Access Token.

ii) POSTMAN Body

iii) The Result

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401051743.13391564143479898344278549788654:50510426063352:2800:584B51B755E6692F4016FB8BC36E5E252177C8A8B3821038A0CBF554D8F33103.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20200401051743.13391564143479898344278549788654:50510426063352:2800:584B51B755E6692F4016FB8BC36E5E252177C8A8B3821038A0CBF554D8F33103.png[/IMG]

Now What?

Well we can do many things like we can subscribe or unsubscribe to a topic, querying or deleting data as a controller or we can send receipts to a developer's receipt processing server using PUSH Kit Server APIs.

For more information, you can click this link https://forums.developer.huawei.com/forumPortal/en/home