Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase : Send notification with REST API

Tags:

Is it possible to send push notification with REST API on Firebase? I can send notifications with Firebase console but i need to send notifications with REST API.

like image 761
cimenmus Avatar asked May 27 '16 19:05

cimenmus


People also ask

How send notification from API with Firebase?

Go to Firebase console — →Project Settings — →Cloud Messaging. To send the message select Body — →Raw — →JSON(application/json). You can send Notification Payload , Data Payload and even both using POSTMAN service.

How do you send FCM messages using FCM REST API from app server?

for url use: https://fcm.googleapis.com/fcm/send and for your server key use your firebase server key. thats literally all. just dont forget to store the device token ID on your server and then you can send messages all day for free to individual users.

What is FCM API?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.


2 Answers

Just for helping,

If anyone wants to use REST POST API, here it is, use the Postman with below configuration

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

Header:

"Content-Type": "application/json",
"Authorization": "key=<Server_key>"

BODY:

{
    "to": "<Device FCM token>",
    "notification": {
      "title": "Check this Mobile (title)",
      "body": "Rich Notification testing (body)",
      "mutable_content": true,
      "sound": "Tri-tone"
      },

   "data": {
    "url": "<url of media image>",
    "dl": "<deeplink action on tap of notification>"
      }
}

That's it. Thanks!!!

If you want to get more details about Rich Notification with FCM, you can check my article on Medium Rich Push Notification with Firebase Cloud Messaging (FCM) and Pusher on iOS platform

like image 145
Ashis Laha Avatar answered Oct 06 '22 19:10

Ashis Laha


I used the below rest API to send notification.

curl -X POST \
  https://fcm.googleapis.com/fcm/send \
  -H 'Authorization: key=AAAAG-oB4hk:APA91bFUilE6XqGzlqtr-M-LRl1JisWgEaSDfMZfHuJq3fs7IuvwhjoGM50i0YgU_qayJA8FKk15Uvkuo7SQtQlVt4qdcrrhvnfZyk_8zRGAskzalFUjr2nA2P_2QYNTfK6X8GbY0rni' \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: c8af5355-dbf2-4762-9b37-a6b89484cf07' \
  -H 'cache-control: no-cache' \
  -d '{
    "to": "ey_Bl_xs-8o:APA91bERoA5mXVfkzvV6I1I8r1rDXzPjq610twte8SUpsKyCuiz3itcIBgJ7MyGRkjmymhfsceYDV9Ck-__ObFbf0Guy-P_Pa5110vS0Z6cXBH2ThnnPVCg-img4lAEDfRE5I9gd849d",
    "data":{
        "body":"Test Notification !!!",
        "title":"Test Title !!!"
    }

}'

Authorization : key=AAAAG-oB4hk:APA91bFUilE6XqGzlqtr-M-LRl1JisWgEaSDfMZfHuJq3fs7IuvwhjoGM50i0YgU_qayJA8FKk15Uvkuo7SQtQlVt4qdcrrhvnfZyk_8zRGAskzalFUjr2nA2P_2QYNTfK6X8GbY0rni

where key is web_server_key from the console and you need to specify the unique registration key which you will get from the app.

enter image description here

"to": "ey_Bl_xs-8o:APA91bERoA5mXVfkzvV6I1I8r1rDXzPjq610twte8SUpsKyCuiz3itcIBgJ7MyGRkjmymhfsceYDV9Ck-__ObFbf0Guy-P_Pa5110vS0Z6cXBH2ThnnPVCg-img4lAEDfRE5I9gd849d" is the FCM registration token from device. Please refer to the below link.

https://firebase.google.com/docs/cloud-messaging/android/client?authuser=0

like image 20
dassum Avatar answered Oct 06 '22 21:10

dassum