Enbbox Docs

Firebase Cloud Messaging (FCM)

Integrate Firebase Cloud Messaging (FCM) with Enbbox for Android and web push notifications. Setup guide with service account credentials.

Overview

Firebase Cloud Messaging (FCM) is Google's cross-platform push notification service for Android, iOS, and web applications.

[!IMPORTANT] FCM requires a Firebase project and a Service Account JSON key file. The legacy server key is deprecated — Enbbox uses the FCM HTTP v1 API with service account credentials.

Prerequisites

  • A Google Firebase account
  • A Firebase project with your app registered
  • Your app must integrate the Firebase SDK to receive push notifications

Step 1: Create a Firebase Project

  1. Go to console.firebase.google.com
  2. Click Add project and enter a project name
  3. Follow the setup wizard to create the project
  4. Add your app platform (Android, iOS, or Web)

Step 2: Generate a Service Account Key

  1. In the Firebase Console, click the gear iconProject Settings
  2. Navigate to the Service accounts tab
  3. Click Generate new private key
  4. Confirm by clicking Generate key — a JSON file will be downloaded
{
  "type": "service_account",
  "project_id": "my-project-123",
  "private_key_id": "abc123...",
  "private_key": "-----BEGIN PRIVATE KEY-----\n...",
  "client_email": "[email protected]",
  ...
}

[!CAUTION] This JSON file contains your private key. Store it securely and never commit it to version control.

Step 3: Connect to Enbbox

  1. Navigate to Integrations in the Enbbox dashboard
  2. Click Add Provider → select PushFCM
  3. Paste the entire Service Account JSON content into the credentials field
  4. Click Test Connection to verify
  5. Activate the integration

Step 4: Register Device Tokens

In your mobile/web app, retrieve the FCM device token and store it in the subscriber's credentials:

// Client-side: get the FCM token
import { getToken } from "firebase/messaging";
const token = await getToken(messaging, { vapidKey: "your-vapid-key" });

// Server-side: store it in Enbbox
import { SubscriberCredentialsApi, Configuration } from "@enbbox/api";

const config = new Configuration({ accessToken: "your-api-key" });
const credentialsApi = new SubscriberCredentialsApi(config);

await credentialsApi.setCredentials("subscriber-123", "fcm", {
  credentials: { device_tokens: [token] },
});

Step 5: Send a Test Notification

import { EventsApi, Configuration } from "@enbbox/api";

const config = new Configuration({ accessToken: "your-api-key" });
const eventsApi = new EventsApi(config);

await eventsApi.triggerEvent({
  name: "order-update",
  to: { subscriberId: "subscriber-123" },
  payload: {
    title: "Order Shipped",
    body: "Your order #1234 has been shipped!",
  },
});

Advanced Configuration

Data Payloads

Send custom data to your app alongside the notification:

overrides: {
  fcm: {
    data: {
      orderId: '1234',
      screen: 'order-detail',
    },
  },
}

Platform-Specific Options

overrides: {
  fcm: {
    android: {
      priority: 'high',
      notification: { sound: 'custom_sound' },
    },
    webpush: {
      notification: { icon: '/icon.png' },
    },
  },
}

Troubleshooting

IssueSolution
Invalid service accountEnsure you're using the full JSON (not just the key)
Token not registeredThe device token may be stale — refresh it on app start
Notification not receivedCheck Firebase Console → Cloud Messaging for delivery reports
Permission deniedEnsure the service account has the cloudmessaging.messages.create permission

On this page