# Integrate push notifications in your app

**Summary:** Get the device FCM token, subscribe and unsubscribe devices with optional topics, link a subscriber to a logged-in member, and report when a user opens the app from a notification.

- Space: [Developers](https://www.subrite.no/developers)
- Source: https://www.subrite.no/developers/push-notifications-app
- Updated: 2026-09-23
- Markdown index: https://www.subrite.no/developers/llms.txt

<a id="step-1-set-up-firebase-in-the-app"></a>
## Step 1: Set up Firebase in the app

The app integration varies between projects and platforms. Follow the guides in the [Firebase docs](https://firebase.google.com/docs) to set up Firebase for your platform of choice.

There should be functionality in place in the app to toggle notifications on and off, entry points for opening the app from a notification, and handling of incoming notifications while the app is running.

<a id="step-2-get-the-device-fcm-token"></a>
## Step 2: Get the device FCM token

When the app user enables notifications, you need the device FCM token to subscribe or unsubscribe.

In React Native, after requesting permissions from the user, you get the token by importing the library and calling `getToken()`:

```javascript
import messaging from '@react-native-firebase/messaging';

const token = await messaging().getToken();
```

Other platforms, like iOS, Android or Flutter, have similar methods available.

<a id="step-3-subscribe-the-device"></a>
## Step 3: Subscribe the device

To subscribe to notifications when the user toggles them on, send the token to the Subrite API. There is an optional array of strings, `topics`, if you want your users to be able to subscribe to specific topics of their interest.

- **Method:** `POST`
- **Route:** `{baseUrl}/api/v1/app-push/subscribe`
- **Authorization:** Bearer token (the M2M token from [Basic setup, step 4](https://www.subrite.no/developers/push-notifications-setup?md=true))
- **Body:** see the example below

<a id="example-body"></a>
### Example body

```json
{
  "provider": "fcm",
  "token": "INSERT FCM TOKEN HERE",
  "topics": [
    "politics"
  ]
}
```

You can use the same call to update the subscription with more or fewer topics.

While topic filtering is on (the default), topics only work if both sides agree:

- The topic strings a device subscribes to here must be identical to the topics your CMS sends when [pushing content](https://www.subrite.no/developers/push-notifications-server?md=true). The comparison is case-sensitive, and one topic in common is enough.
- A device that subscribes with an empty `topics` array, or with topics that never match, only receives notifications sent without topics.
- If you don't intend to use topics at all, send an empty array here, and make sure your CMS doesn't send topics either. Alternatively, the tenant can turn off topic filtering in the admin dashboard (see [Basic setup](https://www.subrite.no/developers/push-notifications-setup?md=true)), so subscribers are notified no matter which topics they have subscribed to.

<a id="step-4-unsubscribe-the-device"></a>
## Step 4: Unsubscribe the device

To unsubscribe from notifications when the user toggles them off, send the same token to the Subrite API, this time as a `DELETE` request.

- **Method:** `DELETE`
- **Route:** `{baseUrl}/api/v1/app-push/subscribe`
- **Authorization:** Bearer token (the M2M token from [Basic setup, step 4](https://www.subrite.no/developers/push-notifications-setup?md=true))
- **Body:** see the example below

<a id="example-body-2"></a>
### Example body

```json
{
  "provider": "fcm",
  "token": "INSERT TOKEN HERE"
}
```

<a id="step-5-optional-link-the-subscriber-to-a-member"></a>
## Step 5 (optional): Link the subscriber to a member

If your app supports login with the Subrite platform, you can link a subscriber with a member. You do **not** use the M2M token for this. Use the JWT that Subrite provides when the user logs in.

- **Method:** `PUT`
- **Route:** `{baseUrl}/api/v1/app-push/linksubscriber`
- **Authorization:** Bearer token (the user's JWT)
- **Body:** see the example below

<a id="example-body-3"></a>
### Example body

```json
{
  "provider": "fcm",
  "token": "INSERT TOKEN HERE"
}
```

<a id="step-6-optional-track-notification-opens"></a>
## Step 6 (optional): Track notification opens

To track a user engaging with the notification, you can notify the Subrite API whenever a user opens the app from a notification. In the payload of the notification, you will find an `itemKey`.

Example React Native code for getting the `itemKey`:

```javascript
// from background state
messaging().onNotificationOpenedApp(
  message => {
    const itemKey = message?.data?.itemKey;
    // send to Subrite API here
  }
)

// from quit state
messaging()
  .getInitialNotification()
  .then(message => {
    const itemKey = message?.data?.itemKey;
    // send to Subrite API here
  });
```

- **Method:** `PUT`
- **Route:** `{baseUrl}/api/v1/app-push/open`
- **Authorization:** Bearer token (the M2M token from [Basic setup, step 4](https://www.subrite.no/developers/push-notifications-setup?md=true))
- **Body:** see the example below

<a id="example-body-4"></a>
### Example body

```json
{
  "itemKey": "a8786532953ba69c7793a5d85c06c84eea1f25eb"
}
```

The app integration is now ready, and you can continue with [integrating the server](https://www.subrite.no/developers/push-notifications-server?md=true).
