Knowband Blog | Ecommerce Modules

How to send push notification from server?

What are push notifications?

Push notifications are the messages that are pushed to mobile from another platform thanĀ the receiving device. Let us consider any mobile app either closed or open. We get some notification from server irrespective of the app is open/closed/minimised. The only condition is that the app should be installed. In such case, we trigger notifications from web server say Firebase. We are pushing the notifications to mobile app from server. Hence these are called push notification.

Firebase providesĀ us API(s) that can be triggered to send the push notification to any device.

Sending Push Notification using Firebase

We can trigger below API provided by the Firebase to send a push notification to any device.

API URL :

https://fcm.googleapis.com/fcm/send

Headers :

Content-Type:application/json

Authorization:key=AAAAR8kVIU:APA91bGaZe_uSKd2EtATPVoIUFGW6E3EwzcfsurUtjMIMIsxdTICC2Wl4BDtiWVupueBaJoQbb1JjAjDDEhDEWXWf3Cp_WXBAO1LkOUwtYPnj7XjeEFW1jqhzW8J1g1IwLinL42t8u

Body :

{
"to":"fqU6X2UAdiI:APA91bEHIZ2MwdsTdIW3_Sk_hvH9ZHbbbzJln4A8n6gYyYH71V5dlxazxWWejcafEOEIHc1mvwxauVodIOgdXrSiaxU0mfyPTKWr47k-8SwlyY30_Mxh8NTA2winTE16JO-KbajD",
"priority":"high",
"mutable_content":true,
"content_available":true,
"notification":{
"title":"Sample title",
"body":"Sample Body Sample Body"
},
"data":{
"title":"Title Title",
"body":"Sample body Sample Body",
"image":"Image Link",
"description":"Sample Description"
}
}