Firebase Integration with ISPCRM for Push Notifications¶
This document provides a step-by-step guide to integrate Firebase Cloud Messaging (FCM) with ISPCRM to send push notifications to users.
Prerequisites¶
- Firebase Project: A Firebase project with Cloud Messaging enabled.
- ISPCRM API Access: Access to the ISPCRM API with a valid Bearer Token.
- Firebase SDK: Integrated Firebase SDK in your Mobile or Web Application.
1. Create a Firebase Project¶
- Go to Firebase Console.
- Click Add Project and follow the setup wizard.
- Enable Cloud Messaging in the Firebase project settings.
2. Obtain Server Key and Sender ID¶
- Go to Project Settings > Cloud Messaging.
- Copy the following:
- Server Key (used for authorization in API requests).
- Sender ID (used in the mobile app configuration).
Example: Server Key¶
AAAApEXAMPLE:APA91bHh8xQ...D9j2Ek
Example: Sender ID¶
123456789012
3. Configure Firebase in Mobile App¶
3.1 Install Firebase SDK¶
For Android, add the following to your build.gradle:
implementation 'com.google.firebase:firebase-messaging:23.0.0'
For iOS, add this to your Podfile:
pod 'Firebase/Messaging'
3.2 Configure google-services.json (Android) or GoogleService-Info.plist (iOS)¶
Download the file from Project Settings > General and place it in the root directory of your app.
4. Save FCM Token in ISPCRM¶
Endpoint¶
POST /api/v1/subscriber/saveFcmToken
This endpoint saves the FCM token for the authenticated subscriber.
Request Body¶
| Parameter | Type | Required | Description |
|---|---|---|---|
fcm_token | string | Yes | The FCM token generated by the Firebase SDK. |
device_type | string | Yes | Type of device (android or ios). |
Example Request¶
curl -X POST "https://yourispcrmdomain/api/v1/subscriber/saveFcmToken" \
-H "Authorization: Bearer YOURAPITOKENHERE" \
-H "Content-Type: application/json" \
-d '{
"fcm_token": "fcm_token_here",
"device_type": "android"
}'
Success Response (200 OK)¶
{
"success": true,
"message": "FCM token saved successfully"
}
5. Send Notification via ISPCRM API¶
Endpoint¶
POST /api/v1/notifications/send
This endpoint sends push notifications to a specific subscriber or group of subscribers.
Request Body¶
| Parameter | Type | Required | Description |
|---|---|---|---|
title | string | Yes | Title of the notification. |
message | string | Yes | Message body of the notification. |
fcm_token | string | No | Specific FCM token to send the notification. |
customer_id | string | No | Customer ID to send notification (optional). |
Example Request¶
curl -X POST "https://yourispcrmdomain/api/v1/notifications/send" \
-H "Authorization: Bearer YOURAPITOKENHERE" \
-H "Content-Type: application/json" \
-d '{
"title": "Payment Reminder",
"message": "Your payment is due tomorrow.",
"customer_id": "12345"
}'
Success Response (200 OK)¶
{
"success": true,
"message": "Notification sent successfully"
}
6. Firebase Notification Payload Example¶
{
"to": "fcm_token_here",
"notification": {
"title": "ISPCRM Alert",
"body": "Your internet plan will expire soon."
},
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"customer_id": "12345"
}
}
7. Error Handling¶
| Error Code | Message | Explanation |
|---|---|---|
401 Unauthorized | Invalid Server Key | Ensure the correct Server Key is used. |
404 Not Found | Subscriber not found | Invalid customer ID or token. |
500 Internal Error | Failed to send notification | Firebase server or ISPCRM error. |
Example Error Response¶
{
"success": false,
"message": "Invalid FCM token"
}
Summary¶
- Obtain Server Key and Sender ID from Firebase.
- Save FCM token in ISPCRM using
/saveFcmToken. - Send notifications using
/notifications/send.
For further assistance, contact our support team at devs@netgroot.com.