Your server environment and FCM

The server side of Firebase Cloud Messaging consists of two components:

  • The FCM backend provided by Google.
  • Your app server or other trusted server environment where your server logic runs, such as Cloud Functions for Firebase or other cloud environments managed by Google.

Your app server or trusted server environment sends message requests to the FCM backend, which then routes messages to client apps running on users' devices.

Requirements for the trusted server environment

Your app server environment must meet the following criteria:

  • Able to send properly formatted message requests to the FCM backend.
  • Able to handle requests and resend them using exponential back-off.
  • Able to securely store server authorization credentials and client registration tokens.

Required credentials for Firebase project

Depending on which FCM features you implement, you may need the following credentials from your Firebase project:

Credential Description
Project ID A unique identifier for your Firebase project, used in requests to the FCM v1 HTTP endpoint. This value is available in the Firebase console Settings pane.
Registration token A unique token string that identifies each client app instance. The registration token is required for single device and device group messaging. Note that registration tokens must be kept secret.
Sender ID A unique numerical value created when you create your Firebase project, available in the Cloud Messaging tab of the Firebase console Settings pane. The sender ID is the same as the project number. The sender ID is used to identify each sender that can send messages to the client app.
Access token A short-lived OAuth 2.0 token that authorizes requests to the HTTP v1 API. This token is associated with a service account that belongs to your Firebase project. To create and rotate access tokens, follow the steps described in Authorize Send Requests.

Choose a server option

You'll need to decide on a way to interact with FCM servers: either using the Firebase Admin SDK or the FCM HTTP v1 API. Because of its support across popular programming languages and its convenience methods for handling authentication and authorization, the Firebase Admin SDK is the recommended method.

Options for interacting with FCM servers include the following:

Firebase Admin SDK

The Firebase Admin SDK handles authenticating with the backend and facilitates sending messages and managing topic subscriptions. With the Firebase Admin SDK, you can:

  • Send messages to individual devices
  • Send messages to topics and condition statements that match one or more topics
  • Send messages to device groups
  • Subscribe and unsubscribe devices to and from topics
  • Construct message payloads tailored to different target platforms

To set up the Firebase Admin SDK, see Add the Firebase Admin SDK to Your Server. If you already have a Firebase project, start with Add the SDK. Also, make sure to enable the Firebase Cloud Messaging API (V1) in the Cloud Messaging settings page for your project. Then, once the Firebase Admin SDK is installed, you can start writing logic to build send requests.

FCM HTTP v1 API

FCM provides the FCM HTTP v1 API for developers who prefer a raw server protocol.

To send a message, the app server issues a POST request with an HTTP header and an HTTP body comprised of JSON key value pairs. For details on the header and body options, see Send a Message using FCM HTTP v1 API.