Skip to main content

Push Notifications API

Device push notification management and delivery.

EdgeBase provides a unified push notification system built on Firebase Cloud Messaging (FCM). Client endpoints handle device token registration, while admin endpoints handle notification delivery and log queries.


Client Endpoints

Auth: Bearer Token required (Authorization: Bearer <accessToken>)

Register Device Token

POST /api/push/register

Register a device's push notification token with EdgeBase. The token is associated with the authenticated user and stored in KV for fast edge-cached lookups.

Request BodyTypeRequiredDescription
deviceIdstringYesUnique device identifier
tokenstringYesDevice push token obtained from the Firebase SDK
platformstringYesDevice platform: "android", "ios", or "web"
{
"deviceId": "device_01J...",
"token": "dGVzdC10b2tlbi1hYmMxMjM...",
"platform": "android"
}

Response 200

{
"id": "device_01J...",
"token": "dGVzdC10b2tlbi1hYmMxMjM...",
"platform": "android",
"userId": "user_123",
"createdAt": "2026-01-01T00:00:00.000Z"
}
ErrorStatusDescription
Missing fields400Required fields not provided
Unauthorized401Invalid or missing token

Unregister Device Token

POST /api/push/unregister

Remove a device's push notification token. This prevents further push notifications from being sent to this device. Called automatically by client SDKs on sign-out.

Request BodyTypeRequiredDescription
tokenstringYesThe device push token to remove
{
"token": "dGVzdC10b2tlbi1hYmMxMjM..."
}

Response 200

{ "ok": true }

Subscribe to Topic

POST /api/push/topic/subscribe

Subscribe all of the authenticated user's registered devices to an FCM topic. Useful for group-based or category-based notifications.

Request BodyTypeRequiredDescription
topicstringYesTopic name to subscribe to
{
"topic": "news"
}

Response 200

{
"ok": true,
"subscribed": 2,
"failed": 0
}
ErrorStatusDescription
Missing topic400topic field not provided
Unauthorized401Invalid or missing token
No devices404No registered devices found for the user

Unsubscribe from Topic

POST /api/push/topic/unsubscribe

Unsubscribe all of the authenticated user's registered devices from an FCM topic.

Request BodyTypeRequiredDescription
topicstringYesTopic name to unsubscribe from
{
"topic": "news"
}

Response 200

{
"ok": true,
"unsubscribed": 2,
"failed": 0
}
ErrorStatusDescription
Missing topic400topic field not provided
Unauthorized401Invalid or missing token
No devices404No registered devices found for the user

Admin Endpoints

Auth: Service Key required (X-EdgeBase-Service-Key header)

Send Push to Single User

POST /api/push/send

Send a push notification to all registered devices of a single user.

Request BodyTypeRequiredDescription
userIdstringYesTarget user ID
titlestringYesNotification title
bodystringYesNotification body text
imagestringNoImage URL for the notification
soundstringNoNotification sound
badgenumberNoBadge count (iOS)
dataobjectNoCustom data payload (e.g., deep link routing)
silentbooleanNoSend as silent/data-only notification
collapseIdstringNoCollapse key for replacing notifications
ttlnumberNoTime-to-live in seconds
fcmobjectNoRaw FCM overrides
{
"userId": "user_123",
"title": "New message",
"body": "You have a new message from Jane",
"data": {
"route": "chat",
"chatId": "chat_456"
}
}

Response 200

{
"ok": true,
"sent": 2,
"failed": 0
}
ErrorStatusDescription
Missing Service Key403X-EdgeBase-Service-Key header not provided
Invalid Service Key401Service Key does not match
User not found404No registered tokens for the specified user

Send Push to Multiple Users

POST /api/push/send-many

Send the same push notification to multiple users at once. Each user's registered devices will all receive the notification.

Request BodyTypeRequiredDescription
userIdsstring[]YesArray of target user IDs
titlestringYesNotification title
bodystringYesNotification body text
imagestringNoImage URL for the notification
soundstringNoNotification sound
badgenumberNoBadge count (iOS)
dataobjectNoCustom data payload
silentbooleanNoSend as silent/data-only notification
collapseIdstringNoCollapse key for replacing notifications
ttlnumberNoTime-to-live in seconds
fcmobjectNoRaw FCM overrides
{
"userIds": ["user_1", "user_2", "user_3"],
"title": "System update",
"body": "A new version is available",
"data": {
"route": "settings"
}
}

Response 200

{
"ok": true,
"sent": 5,
"failed": 1
}

Send Push to Raw FCM Token

POST /api/push/send-to-token

Send a push notification directly to any FCM token, bypassing user-based routing. Useful for testing, external integrations, or when you manage tokens outside EdgeBase.

Request BodyTypeRequiredDescription
tokenstringYesFCM device push token
payloadobjectYesPush payload (see Push Payload)
platformstringNoDevice platform: "android", "ios", or "web" (default: "web")
{
"token": "dGVzdC10b2tlbi1hYmMxMjM...",
"payload": {
"title": "Direct notification",
"body": "This goes to one specific device"
},
"platform": "android"
}

Response 200

{
"sent": 1,
"failed": 0
}

Send Push to Topic

POST /api/push/send-to-topic

Send a push notification to all devices subscribed to an FCM topic.

Auth: Service Key required

Request BodyTypeRequiredDescription
topicstringYesFCM topic name
payloadobjectYesPush payload (see Push Payload)
{
"topic": "news",
"payload": {
"title": "Breaking News",
"body": "Something important happened"
}
}

Response 200

{
"success": true
}
ErrorStatusDescription
Missing Service Key403X-EdgeBase-Service-Key header not provided
Invalid Service Key401Service Key does not match
Missing fields400topic or payload not provided
Push not configured503FCM credentials not configured

Broadcast Push to All Devices

POST /api/push/broadcast

Broadcast a push notification to all registered devices via the FCM all topic. Every device is auto-subscribed to the all topic on registration.

Auth: Service Key required

Request BodyTypeRequiredDescription
payloadobjectYesPush payload (see Push Payload)
{
"payload": {
"title": "System Announcement",
"body": "Scheduled maintenance tonight at 2 AM"
}
}

Response 200

{
"success": true
}
ErrorStatusDescription
Missing Service Key403X-EdgeBase-Service-Key header not provided
Invalid Service Key401Service Key does not match
Missing payload400payload not provided
Push not configured503FCM credentials not configured

Update Device Token Metadata

PATCH /api/push/tokens

Update metadata for a specific device token. Useful for attaching custom attributes (e.g., locale, preferences) to a device.

Auth: Service Key required

Request BodyTypeRequiredDescription
userIdstringYesThe user who owns the device
deviceIdstringYesThe device ID to update
metadataobjectYesCustom metadata object to attach
{
"userId": "user_123",
"deviceId": "device_01J...",
"metadata": {
"locale": "ko",
"notifyMarketing": true
}
}

Response 200

{ "ok": true }
ErrorStatusDescription
Missing Service Key403X-EdgeBase-Service-Key header not provided
Invalid Service Key401Service Key does not match
Missing fields400userId, deviceId, or metadata not provided
Device not found404No matching device for the user

List User's Device Tokens

GET /api/push/tokens?userId=:userId

Retrieve all registered device tokens for a specific user.

Auth: Service Key required

Query ParameterTypeRequiredDescription
userIdstringYesThe user ID to look up
curl "https://your-project.edgebase.dev/api/push/tokens?userId=user_123" \
-H "X-EdgeBase-Service-Key: <serviceKey>"

Response 200

{
"tokens": [
{
"id": "device_01J...",
"token": "dGVzdC10b2tlbi1hYmMxMjM...",
"platform": "android",
"createdAt": "2026-01-01T00:00:00.000Z"
},
{
"id": "device_01K...",
"token": "d2ViLXRva2VuLXh5ejc4OQ...",
"platform": "web",
"createdAt": "2026-01-15T00:00:00.000Z"
}
]
}

Query Push Notification Logs

GET /api/push/logs

Query push notification delivery logs. Logs are retained for 24 hours and include delivery status and error details for debugging.

Auth: Service Key required

Query ParameterTypeRequiredDescription
userIdstringNoFilter logs by user ID
limitnumberNoMaximum number of log entries to return (default: 50)
curl "https://your-project.edgebase.dev/api/push/logs?userId=user_123&limit=20" \
-H "X-EdgeBase-Service-Key: <serviceKey>"

Response 200

{
"logs": [
{
"id": "log_01J...",
"userId": "user_123",
"status": "sent",
"platform": "android",
"title": "New message",
"body": "You have a new message from Jane",
"timestamp": "2026-01-20T12:30:00.000Z",
"error": null
},
{
"id": "log_01K...",
"userId": "user_123",
"status": "failed",
"platform": "ios",
"title": "New message",
"body": "You have a new message from Jane",
"timestamp": "2026-01-20T12:30:00.000Z",
"error": "InvalidRegistration"
}
]
}
Log StatusDescription
sentNotification delivered successfully to FCM
failedDelivery failed (see error field for details)
removedDevice token was invalid and has been automatically removed

Error Format

All Push API errors follow the standard EdgeBase error format:

{
"code": 400,
"message": "Validation failed.",
"data": {
"platform": { "code": "invalid_value", "message": "Must be 'android', 'ios', or 'web'." }
}
}
HTTP StatusMeaning
400Bad request or validation failure
401Authentication required (missing token or Service Key)
403Access denied (invalid Service Key)
404User or resource not found
429Rate limit exceeded
500Internal server error