0

I wrote an app some time ago, and now I need to use push notifications. I used Firebase to receive notifications; so far, so good.

Now, I need the admin version of my app to be able to create those notifications, instead of sending them via the console. This documentation says that I should create a POSTrequest, but it doesn't explain what URL I sould POST to.

What is the URL to use?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ilvidel
  • 322
  • 1
  • 4
  • 13
  • 1
    "To send a message, the application server issues a POST request. For example: https://fcm.googleapis.com/fcm/send " did you not read that part, or is there something else I am missing? – njzk2 May 30 '16 at 20:59

2 Answers2

1

Take a look at:

Sending downstream messages

POST REQUEST:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

to is the device key. Autorization header is your FCM key.

Tiago Luz
  • 129
  • 6
  • thanks for your reply. I thought my app's name should be somewhere in the url. However, that is to send to ONE device. How can I send a notification to _all_ devices? – ilvidel Jun 12 '16 at 11:15
  • I don't know if there's a "magic" way to send broadcast messages, probably don't. You will have to do a post request to each device. – Tiago Luz Dec 05 '16 at 18:57
1

To send notification like the firebase console, make POST request like this

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA  

{
   "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
   "notification" : {
       "body" : "great match!",
       "title" : "Portugal vs. Denmark",
       "icon" : "myicon"
    }
 }

it's important to use "notification" as a keyword

see this: https://firebase.google.com/docs/cloud-messaging/concept-options

Andrea Scalabrini
  • 1,442
  • 2
  • 18
  • 25