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)
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:
- Better security via access tokens
- More efficient customization of messages across platforms
- 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.
☛ Send Notification using OAuth 2.0 Playground :-
- Open Google Developers OAuth 2.0 Playground https://developers.google.com/oauthplayground
- Navigate to Step 1 (Select & authorize APIs) → Select “
Firebase Cloud Messaging API v1
” and click “Authorize API’s
” button.
- 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.
- Navigate to Step 2 (Exchange authorization code for tokens) → Click “
Exchange authorization code for tokens
” button.
This will generate “Refresh token
” and “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:sendHTTP 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"
}
}
}
- Click “
Send the request
” and Voila, you have successfully send the push notification using FCM HTTP v1
☛ Send Notification using Postman :-
Endpoint
: https://fcm.googleapis.com/v1/projects/<Project Id>/messages:sendMethod
: POSTHeaders
:-
-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