Hup2

Testing sending notifications

So you have your notifications set up on your page that does all the permission stuff but no one seems to tell you how to send notifications to it.

Hopefully this page might help someone with this

For this to work you need to get your server key from the firebase console

You also need to have the token of the page your are wanting to send to, so add

console.log('token is :', currentToken);

to messaging.getToken().then(function(currentToken) {}

In the console of the web browser developer section you should see the token being displayed

Once you have this, you might want to stop displaying it.

Download postman from https://www.getpostman.com/

In Postman start a new post request

put https://fcm.googleapis.com/fcm/send in the post field.

set up two headers.

KEY VALUE
Authorization Key=YOUR SERVER KEY FROM FIREBASE
Content-Type application/json


In the body put

{
"notification": {
"title": "Testing, thanks to hup2",
"body": "Hopefully this works as I have been getting nowhere for ages",
"icon": "firebase-logo.png"
},
"to": "TOKEN FROM YOUR PAGE THAT GRANTED PERMISSION FOR NOTIFICATIONS"
}

Click send

Hopefully you have just been sent a notification

Now this is great but might not be all that useful if you had to go into postman each time you had to send a notification

However, in postman under the send button you will see the word Code. Click this and you will see postman provides the code needed for various programming langauges.

I have used the PHP cURL version and the JavaScript XHR version which both worked well. With these you can change the code to pick up any tokens you have saved in your database to send to multiple users.

Home