How do I send Firebase push notification using n8n

Description:

Since I want to send a firebase push notiffication with FCM token, the http request requires both the FCM token and an auth token from google, how do I implement this?

Information on your n8n setup

  • n8n version: 1.118.2
  • Database (default: SQLite): postgresDB
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker inside GCP VM
  • Operating system: Linux VM

@Punosie
use the OAuth2 API credential.

here is the setup i use for fcm v1:

Go to Firebase Console → Project Settings → Service Accounts → Generate New Private Key

  • In n8n, create a new OAuth2 API credential.
  • Grant Type: Service Account (this is important).
  • Token URL: https://oauth2.googleapis.com/token
  • Scope: https://www.googleapis.com/auth/firebase.messaging (this is what allows push notifications).
  • Email & Private Key: Copy them straight from Private key file.

in The HTTP Request Node:

  • Method: POST
  • URL: https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
  • Authentication: Select the credential you just made.

Is this the correct OAuth2 credential ?

I don’t see anyplace to add Token URL.

no it isn’t , go to your credential page and search for “OAuth2 API” (literally just those words).


I dont see service account option in this :confused:

my bad. i totally sent you down the wrong path.

n8n changed how these are grouped. the generic “OAuth2 API” doesn’t have the service account dropdown anymore.

you need to search the credentials list for Google Service Account instead.

it’s actually way easier now:

  1. paste your Email and Private Key directly into it.
  2. flip the toggle for Set up for use in HTTP Request node.
  3. dump your https://www.googleapis.com/auth/firebase.messaging scope into the new box that pops up.

select that new credential in your http node and it’ll handle the token rotation properly.

what all permissions do I need to give to the service account then ?

@Punosie

in the google cloud console (IAM & Admin section), you need to assign your service account the Firebase Cloud Messaging API Admin role,make sure you select exactly that one.

this video walks through the exact steps of navigating the google console for FCM v1 if you want a visual on where to assign those specific permissions.

… Firebase Cloud Messaging API (v1) Tutorial …

Thanks a lot

1 Like

Service Account Credential

Error

Access goven to the service account

API Call Setup

I am still unable to use this with the service account method. Its working with OAuth but I want to use the service account only.

Its working now !!! :blush:

The option to add scopes was available only after enabling this HTTP Request option.
Thanks Bro!

1 Like

it is already in here , happy that i could help you!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.