Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
2,009
What is a push notification?

It’s an alert that popus up on the user device that prompts us to do something. The push capabilities in mobile services are that developers do not need to care about implanting code to talk to APNS or FCM.

Details about the push notification are present over here

A detailed tutorial on how to enable push notification on MDK is available over here

In this blog we are going to concentrate on how to send push notifications via the REST API.

  1. The above-mentioned tutorial is a prerequisite.

  2. Navigate to the application and select to Mobile Push Notification feature, and select the service key tab.

  3. Create a service key by pressing + icon, for our demo we would create a “push_single” role which will allow us to send a push notification to a single user or device.



























    Properties Descriptions
    Alias

    A human readable name for the service key, from 1-64 characters, and used as the username to authenticate a request. Also used when an audit log record is created. Required.

     
    API Key

    The API-key that is sent in the request header and used as the password to authenticate a request. The API-key cannot be edited.

     
    Roles

    The roles that are assigned to this service key. Required.

     
    URL

    The URL used to access the service instance. The URL cannot be edited.

     
    Actions

    You can delete a service key, but you cannot edit one. To change a service key, you must delete it, and then create a new one.

     


  4. This generates an API key along with a URL which can be used in 3rd party clients like POSTMAN.

  5. Now lets go ahead and open postman, create a new request by pressing + icon.

    1. Change the request to POST.

    2. From the link we have the request example. In our scenario we are sending a push notification to a particular (user or users). The url for this scenario is ( {servicepath}/mobileservices/push/v1/backend/applications/{applicationId}/notifications/users ). The service path is the url from the service key tab, choose the right url if you have multiple keys. The applicationId is the app id of your application.

    3. Select Authorization, and from drop down “Type” select “API Key”. On the right hand side you need to enter values for “Key” and “Value”



















      Properties Value
      Key X-API-Key
      Value <<API key from service key tab>>
      Add to Header


    4. Add below headers















      Properties Value
      Content-type application/json
      Accept application/json


    5. The Body of the message is below. Choose “raw” as the body option and the type is “JSON”. Please note – the user ID is case sensitive and matches how it’s returned by the identity provider.











      {

      "users": [

      "user1", "user2", ...

      ],

      "notification": {

      "alert": "Hello, this is your push notification from Backend System",

      "sound": "default",

      "apns": {

      "category": "immediate-action",

      "customValues": "{\"order\" : \"4711-2314\"}"

      },

      "gcm": {

      "delayWhileIdle": true,

      "timeToLive": 123456

      }

      }

      }
       


    6. Click on send button, your mobile device should receive the message.




Conclusion - With this one should be able to send push notifications from 3rd party systems.