Overview
Client-mode REST API connectors for Firebase: write device state, append events, and query history in the Realtime Database, and upsert, merge, and query Cloud Firestore documents from MQTT. This is one of the templates in the Firebase Realtime Database and Cloud Firestore REST API app (firebase-realtime-database-and-cloud-firestore). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector). See Firebase Realtime Database and Cloud Firestore for the package overview.
Not yet verified against the live vendor API: Needs a lab Firebase project: project id, RTDB instance URL (https://<db>-default-rtdb.firebaseio.com or <region>.firebasedatabase.app), and a Google OAuth2 access token from a service account (scopes userinfo.email + firebase.database for RTDB; roles/datastore.user with datastore or cloud-platform scope for Firestore), Hub secret FIREBASE_ACCESS_TOKEN. Gate: RTDB PUT devices/press-01/state.json 200 + POST events.json 200 + GET 200; Firestore PATCH documents/devices/press-01 200 + runQuery 200. No Firebase/Google credentials on the factory box. Emulator smoke 13/13 (11 events + 2 rules denials) and real-endpoint probes (public RTDB GET 200; writes 401; Firestore invalid token 401) are partial evidence only.
Auth
Bearer {value.json.access_token} on both connectors. RTDB: Google OAuth2 SA token (userinfo.email + firebase.database); alt ?access_token= or Firebase ID token via ?auth=. Firestore: Google OAuth2 SA token (roles/datastore.user) or Firebase ID token (rules apply). Hub secret FIREBASE_ACCESS_TOKEN. Auth headers used by the template:Authorization: Bearer {value.json.access_token}.
Template parameters
BASE_ADDRESS default: https://firestore.googleapis.com.
Events
Deploy
Get the template card (JSON withtemplate and metadata) from the broker, then deploy the connector:
BASE_ADDRESS already filled in:
-addRoute (do not include ADD METADATA).
Usage example
CallUpsertDocument by publishing a JSON payload to its request topic, and read the reply on the response topic:

