Registers a Firebase Cloud Messaging (FCM) token for push notifications on mobile devices
cURL
curl --request POST \ --url http://localhost:3000/api/notifications/register-fcm-token \ --header 'Content-Type: application/json' \ --data ' { "token": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]", "deviceId": "device_abc123", "platform": "ios" } '
{ "success": true, "message": "FCM token registered successfully" }
deviceId
Device.deviceId
import * as Notifications from "expo-notifications"; import * as Device from "expo-device"; import { Platform } from "react-native"; // Request permissions and get token const { status } = await Notifications.requestPermissionsAsync(); if (status !== "granted") { console.log("Permission not granted"); return; } const token = (await Notifications.getExpoPushTokenAsync()).data; // Register with backend await fetch("/api/notifications/register-fcm-token", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token, deviceId: Device.deviceId, platform: Platform.OS, }), });
Firebase Cloud Messaging token from the device
"ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"
Unique identifier for the device
"device_abc123"
Platform of the device
ios
android
web
"ios"
FCM token registered successfully
Whether the operation was successful
true
Success message
"FCM token registered successfully"