Firebase Cloud Messaging
Introduction#
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
Official Documentation: https://firebase.google.com/docs/cloud-messaging/
Sending Downstream Messages via cURL
You can test sending messages using the FCM REST API by sending a request through cURL.
curl --header "Authorization: key=<API_KEY>" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
Syntax retrieved from here.
The API_KEY
indicated above is referring to the Server Key that can be seen in your Firebase Console’s Cloud Messaging Tab.
The part where:
"{\"registration_ids\":[\"ABC\"]}"
is, can be replaced with your own payload. See the FCM HTTP Protocol Documentation for more details.
Sending Downstream Messages using Postman
To do this in Postman, you simply have to set the following:
- Set request type to
POST
- In the Headers, set the following:
- Content-Type = application/json
- Authorization = < Your FCM Server Key > (See your Firebase Console’s Cloud Messaging Tab)
- Set the payload parameters in the Body (in this example, we used the raw option, see screenshot (2))
- Send the request to https://fcm.googleapis.com/fcm/send
Screenshots:
Note: Always keep your Server Key a secret. Only a portion of my key is visible here so it should be fine.
Notice that the request was a success with the message_id
in the response.