Configure Push Notifications
The API server requires its own set of credentials to authenticate with and send notifications through push provider services like Firebase Cloud Messaging (FCM) and OneSignal. This guide explains how to obtain the required keys for each service.
Firebase Cloud Messaging (FCM)
Section titled “Firebase Cloud Messaging (FCM)”To send notifications via FCM, the server needs a Service Account Key. This is a secure JSON file that grants the server administrative access to your Firebase project’s services.
-
Navigate to your Firebase Project
Open the Firebase Console and select the same project you are using for the mobile client.
-
Generate a New Private Key
- Go to Project Settings (click the gear icon ⚙️ next to “Project Overview”).
- Select the Service accounts tab.
- Click the Generate new private key button.
A JSON file will be downloaded to your computer. This file contains the credentials your server needs.
-
Update Your
.envFileOpen the downloaded JSON file and find the following values:
project_idclient_emailprivate_key
Copy these values into your API server’s
.envfile..env # --- Firebase Cloud Messaging (FCM) ---FIREBASE_PROJECT_ID="<your-project-id-from-the-json-file>"FIREBASE_CLIENT_EMAIL="<your-client-email-from-the-json-file>"FIREBASE_PRIVATE_KEY="<your-private-key-from-the-json-file>"
OneSignal
Section titled “OneSignal”To send notifications via OneSignal, the server needs your App ID and a REST API Key.
-
Navigate to Your OneSignal Dashboard
Open your OneSignal Dashboard and select your application.
-
Find Your Keys & IDs
- Go to Settings.
- Select the Keys & IDs tab.
You will find your
App IDandREST API Keyhere. -
Update Your
.envFileCopy these two values into your API server’s
.envfile..env # --- OneSignal ---ONESIGNAL_APP_ID="<your-onesignal-app-id>"ONESIGNAL_REST_API_KEY="<your-onesignal-rest-api-key>"