Step-by-step guide for integrating Firebase Cloud Messaging (FCM) with Courier, including setup instructions, token management with or without SDKs, sending messages, using overrides, and enabling automatic formatting.
INFOBefore you begin, ensure that you have created a Firebase project. If you haven’t done so already, create a new project here.
The recommended approach to set up Firebase Cloud Messaging (FCM) with Courier is to use a Courier Mobile SDK. All Courier Mobile SDKs automatically sync FCM tokens to Courier and manage them for you. This allows you to send push notifications directly to a user_id instead of managing FCM tokens manually.
MANUAL IMPLEMENTATION REQUIREMENTSWhen implementing FCM without a Courier Mobile SDK, you will need to:
Sync, store, and manage your users’ FCM tokens. This may require creating entries in your database, deploying separate endpoints, and adding extra development time that can be avoided by using a Courier Mobile SDK.
Manually make a request to the trackingUrl if you want Courier delivery and click tracking.
Here’s a common example request you can make to the send API, demonstrating:
providers.firebase-fcm.override.body.data.YOUR_CUSTOM_KEY for adding custom data to your payload. This is typically used for opening a specific screen in your app when the user interacts with a push notification. Firebase requires the data key to be flat. More details about FCM custom data can be found here.
providers.firebase-fcm.override.body.apns for applying iOS-specific values. You can learn more about these here.
PUSH SOUND & BADGINGSounds and badges can only be configured in the override schema of a send request at this time, and are not compatible with a template field attached. If your push notifications require sounds and badges, then we recommend shaping your push request with sound and badge in the override as shown below.
When working with a working with a Courier Mobile SDK, Courier can automatically format the FCM payload to provide a better developer experience. You can toggle this feature in the Courier FCM Provider Configuration.
When enabled, this feature:
Automatically delivers Android push notifications in the background. This allows for more accurate push notification delivery tracking and the ability to use your own custom Android notification style consistently.
Here is an example of what the formatted send request looks like when this setting is enabled:
Copy
Ask AI
curl --request POST \ --url https://api.courier.com/send \ --header 'Authorization: Bearer YOUR_AUTH_KEY' \ --header 'Content-Type: application/json' \ --data '{ "message": { "to": { "user_id": "YOUR_USER_ID" }, "content": { "title": "Hey there 👋", "body": "Have a great day 😁" }, "routing": { "method": "all", "channels": [ "firebase-fcm" ] }, "firebase-fcm": { "override": { "notification": null, // Prevents Android system tray from taking over notification presentation "data": { // Used by Courier Android SDK to present your customized notification and track notification delivery in all Android states "title": "Hey there 👋", "body": "Have a great day 😁" }, "apns": { "payload": { "aps": { "mutable-content": 1, // Used by the Courier iOS SDK Notification Service Extension "sound": "ping.aiff", // Provides a default sound or vibration if iOS device ringer is off "alert": { "title": "Hey there 👋", "body": "Have a great day 😁" } } } } } } }}'