TESTING FCM PUSH NOTIFICATION (HTTP v1)

Testing FCM Push Notification (HTTP v1) through OAuth 2.0 Playground/Postman/Terminal — Part 2

Tutorial to test Firebase Cloud Messaging (FCM) Push Notification (HTTP v1) through OAuth 2.0 Playground or Postman or Terminal (curl command)

Apoorv Garg

--

FCM (HTTP v1)+ Postman / Terminal / OAuth 2.0 Playground → Send Push Notification

In continuation of my previous post ( Testing FCM Push Notification through Postman/Terminal — Part 1 ), in this article, we will explore how to send a Firebase Cloud Messaging (FCM) Push Notification using the latest FCM HTTP v1 API, through OAuth 2.0 Playground or Postman or Terminal (curl command).

If you are new to Firebase Cloud Messaging (FCM) or want to understand other methods (Legacy FCM HTTP Protocol or Notifications composer) of sending Push Notification, then please follow my previous post here.

Why use or migrate to FCM HTTP v1 ?

As per the firebase documentation, this is the most up-to-date and flexible approach for sending messages to multiple platforms.

Also, the HTTP v1 API has these advantages over the legacy API:

  1. Better security via access tokens
  2. More efficient customization of messages across platforms
  3. More extendable and future-proof for new client platform versions

FCM HTTP v1 Protocol + OAuth 2.0 Playground / Postman / Terminal

Send a message through OAuth 2.0 Playground or Postman or Terminal (curl command)

Copy <Project ID> from Firebase Console → Select Project → Project Settings.
This Project Id will be required in further step while setting up Endpoint.

Copy <Project ID>

☛ Send Notification using OAuth 2.0 Playground :-

Select FCM API v1
  • You will be redirected to Authentication and needs permission for Google OAuth 2.0 Playground to view and manage the GCP services.
    Click “Allow” button.
Authenticate and Grant permission
  • Navigate to Step 2 (Exchange authorization code for tokens) → Click “Exchange authorization code for tokens” button.
    This will generate “Refresh token” and “Access token”.
Generate and Copy <Access token>

Copy the generated “Access token” as you will require it, if you want to send a message through Postman Or Terminal.

  • Navigate to Step 3 (Configure request to API) and add the following details :

Request URI : https://fcm.googleapis.com/v1/projects/<Project Id>/messages:send
HTTP Method : POST

Click “Enter request body” and add the payload in the Request Body:

{
"message": {
"token": "FCM_TOKEN",
"data": {
"body": "Body of Your Notification in data",
"title": "Title of Your Notification in data",
"key_1": "Value for key_1",
"key_2": "Value for key_2"
}
}
}
Add the message payload
  • Click “Send the request” and Voila, you have successfully send the push notification using FCM HTTP v1
Send push notification using FCM HTTP v1

☛ Send Notification using Postman :-

Endpoint : https://fcm.googleapis.com/v1/projects/<Project Id>/messages:send
Method : POST
Headers :-
-Authorization : Bearer <Access token>
-Content-Type : application/json

Add the payload in Body → Raw → JSON & click Send

{
"message": {
"token": "FCM_TOKEN",
"data": {
"body": "Body of Your Notification in data",
"title": "Title of Your Notification in data",
"key_1": "Value for key_1",
"key_2": "Value for key_2"
}
}
}

☛ Send Notification using Terminal :-

curl --location --request POST 'https://fcm.googleapis.com/v1/projects/<Project Id>/messages:send' \
--header 'Authorization: Bearer <Access token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"message": {
"token": "FCM_TOKEN",
"data": {
"body": "Body of Your Notification in data",
"title": "Title of Your Notification in data",
"key_1": "Value for key_1",
"key_2": "Value for key_2"
}
}
}'

References:
1.https://firebase.google.com/docs/cloud-messaging/migrate-v1
2.https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#Notification

Finally, we successfully send Push Notification using FCM (HTTP v1) through OAuth 2.0 Playground/Postman/Terminal.

Make sure you give this post 50 claps👏 and follow if you enjoyed this post and want to see more.

Thank you for reading. ❤️

Connect with me: LinkedIn

--

--

Apoorv Garg

Senior Consultant at GlobalLogic | iOS app developer | AWS Certified Solutions Architect - Associate