> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Firebase Cloud Messaging (HTTP v1)

> Client-mode REST API connector for a curated Firebase Cloud Messaging HTTP v1 slice: send notification messages to a device token or topic, and send data-only messages for app sync

Technical Preview

## Overview

A client-mode connector for a **curated messaging** slice of the [Firebase Cloud Messaging HTTP v1 API](https://firebase.google.com/docs/reference/fcm/rest):

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| POST messages:send (token/topic) | `POST /v1/projects/{project_id}/messages:send` | Notification to registration token or topic |
| POST data message (app sync) | `POST /v1/projects/{project_id}/messages:send` | Data-only `message.data` (same endpoint) |

Default `BASE_ADDRESS` is `https://fcm.googleapis.com`. Topics use `messaging/fcm/<object>/<verb>`.

> [!NOTE]
>
> Auth is **OAuth 2.0 Bearer** from a Google service account with scope `https://www.googleapis.com/auth/firebase.messaging`. Prefer Hub secrets `FCM_ACCESS_TOKEN` and project id `FCM_PROJECT_ID` (alias `FIREBASE_PROJECT_ID`). Status remains blocked until an authenticated live smoke succeeds.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — Firebase Cloud Messaging HTTP v1
# Auth: Authorization: Bearer {value.json.access_token}
# BASE_ADDRESS: https://fcm.googleapis.com

DEFINE ROUTE FirebaseCloudMessagingRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://fcm.googleapis.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Sendmessage
        WITH SOURCE_TOPIC "messaging/fcm/message/send"
        WITH DESTINATION_TOPIC "messaging/fcm/message/send/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/projects/{value.json.project_id}/messages:send"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Senddatamessage
        WITH SOURCE_TOPIC "messaging/fcm/message/send-data"
        WITH DESTINATION_TOPIC "messaging/fcm/message/send-data/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/projects/{value.json.project_id}/messages:send"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
```

## Events

| Event | Method | Endpoint | Request topic | Response topic |
| - | - | - | - | - |
| Sendmessage | POST | `/v1/projects/{project_id}/messages:send` | `messaging/fcm/message/send` | `messaging/fcm/message/send/response` |
| Senddatamessage | POST | `/v1/projects/{project_id}/messages:send` | `messaging/fcm/message/send-data` | `messaging/fcm/message/send-data/response` |

## Auth

1. Create a [Firebase / Google Cloud service account](https://firebase.google.com/docs/cloud-messaging/auth-server) with permission to use FCM (scope `https://www.googleapis.com/auth/firebase.messaging`).
2. Exchange a signed JWT for a short-lived access token at `https://oauth2.googleapis.com/token` (or use Application Default Credentials / `gcloud` offline). Store the token in Hub as `FCM_ACCESS_TOKEN`.
3. Set connector `BASE_ADDRESS` to `https://fcm.googleapis.com`.
4. Pass `access_token` and `project_id` on MQTT JSON payloads so the Authorization header and path resolve. Put the FCM `message` object (and optional `validateOnly`) in the same JSON — `{payload}` is the HTTP body.
5. Never commit service-account JSON, `GOOGLE_APPLICATION_CREDENTIALS` files, or live tokens.
6. Successful send returns **HTTP 200** with a `Message` including `name`. Use `validateOnly: true` for dry-run smokes.

## Example payloads

**sendMessage (token notification):**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "project_id": "YOUR_FIREBASE_PROJECT_ID",
  "access_token": "YOUR_FCM_ACCESS_TOKEN",
  "message": {
    "token": "YOUR_DEVICE_REGISTRATION_TOKEN",
    "notification": {
      "title": "Coreflux alarm — Zone A",
      "body": "RMS exceeded limit on Zone A"
    }
  }
}
```

**sendMessage (topic):**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "project_id": "YOUR_FIREBASE_PROJECT_ID",
  "access_token": "YOUR_FCM_ACCESS_TOKEN",
  "message": {
    "topic": "plant-alarms",
    "notification": {
      "title": "Plant-wide alert",
      "body": "Line 3 stopped"
    }
  }
}
```

**sendDataMessage (app sync):**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "project_id": "YOUR_FIREBASE_PROJECT_ID",
  "access_token": "YOUR_FCM_ACCESS_TOKEN",
  "message": {
    "token": "YOUR_DEVICE_REGISTRATION_TOKEN",
    "data": {
      "device_id": "zone-a-vib-01",
      "metric": "vibration_rms",
      "value": "12.4"
    }
  }
}
```

**validateOnly dry-run:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "project_id": "YOUR_FIREBASE_PROJECT_ID",
  "access_token": "YOUR_FCM_ACCESS_TOKEN",
  "validateOnly": true,
  "message": {
    "topic": "coreflux-smoke",
    "notification": { "title": "smoke", "body": "validateOnly" }
  }
}
```

## Install

1. The template ships with the broker. List it with `-listTemplates` or fetch it from the Hub catalog.
2. Deploy with `-addRoute` from `FirebaseCloudMessagingRestApi.lot` (not `hub-metadata.lot`).

## See also

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API Apps](/latest/lot-language/routes/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.