Google are deprecating the legacy HTTP protocol used for sending Firebase Cloud Messaging push notifications in june 2024. Their migration guide only mentions how to migrate to the HTTP v1 using any of the SDK's for Node.js, Java, Python, Go or C#.
The main hurdle seems to be the authentication procedures required with HTTP v1. Looking at the guides for Firebase Authentication, there also only seem to be options for Node.js, Java, Python, Go or C#.
So what if I want to use some other language which doesn't have an SDK? Can it be done with raw HTTP requests?
The wire protocol for sending messages through Firebase Cloud Messaging through the v1 REST API is fully documented, like with this code snippet from the documentation on sending messages to specific devices:
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"body":"This is an FCM notification message!",
"title":"FCM Message"
}
}
}
You can write your own code that sends this message format against the same end point, and bypass the need for an SDK.
Authorizing a request to this API is documented here, which says:
The FCM HTTP v1 API authorizes requests with a short-lived OAuth 2.0 access token. To mint this token, you can use Google Application Default Credentials (in Google server environments) and/or manually obtain the required credentials from a JSON private key file generated for a service account.
While the documentation only contains code snippets using SDKs to mint an OAuth 2 token, you can use any approach you want to get the OAuth 2 token. For example, searching for get an oath 2 token from google without sdk leads to this promising result : How to get an access token from Google without an api library?.
These also looks promising:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With