Prompt
How do I send push notifications from my backend API?
Latest observation
Oct 14, 2026
OpenAI APIWeb search: off
To send push notifications from your backend API, you usually:
-
Choose a push provider
- Mobile: Firebase Cloud Messaging (FCM), Apple Push Notification service (APNs)
- Web: Web Push (often via FCM or VAPID)
- Many apps use FCM as a single API for Android, iOS, and web.
-
Register devices on the client
- Your app gets a device token / push token from the push service.
- Send that token to your backend and store it associated with the user/device.
-
Have the backend call the push service
- Your API sends a request to the provider using the saved token(s).
- The provider delivers the notification to the device.
Typical backend flow
1) Client gets a push token
Example:
- Android app gets an FCM token
- iPhone app gets an APNs token or FCM token
- Web app gets a browser push subscription/token
2) Client sends token to your backend
Your API stores it:
POST /api/push-tokens
{
"userId": "123",
"token": "fcm_device_token_here",
"platform": "android"
}
3) Backend sends notification
When something happens:
- order shipped
- message received
- password reset
- reminder due
Your backend looks up the token(s) and calls the push provider.
If you use Firebase Cloud Messaging (common choice)
Backend request to FCM HTTP v1
Your backend sends a POST to Google’s FCM endpoint with OAuth credentials.
Example payload:
{
"message": {
"token": "DEVICE_TOKEN",
"notification": {
"title": "Hello",
"body": "You have a new message"
},
"data": {
"type": "new_message",
"chatId": "abc123"
}
}
}
What you need
- Firebase project
- Service account credentials on the backend
- Store device tokens in your database
Example in Node.js using Firebase Admin SDK
import admin from "firebase-admin";
import serviceAccount from "./serviceAccountKey.json" assert { type: "json" };
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
async function sendPush(token) {
const message = {
token,
notification: {
title: "Hello",
body: "You have a new alert",
},
data: {
type: "alert",
id: "123",
},
};
const response = await admin.messaging().send(message);
console.log("Sent:", response);
}
Example in Python with FCM Admin SDK
import firebase_admin
from firebase_admin import credentials, messaging
cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred)
def send_push(token):
message = messaging.Message(
notification=messaging.Notification(
title="Hello",
body="You have a new alert"
),
data={
"type": "alert",
"id": "123"
},
token=token,
)
response = messaging.send(message)
print("Sent:", response)
Important best practices
- Store tokens securely and update them when they change
- Remove invalid tokens when the provider says they’re expired
- Use topics or segments for broadcasting to groups
- Don’t put secrets in the app
- backend credentials only
- Separate notification content from business logic
- Queue notification jobs if sending many at once
If you’re sending to many users
Use:
- device tokens for individual users
- topics / subscriptions for broadcast groups
- message queue for high scale
Example:
- “all users”
- “users in New York”
- “premium customers”
Recommended architecture
- Client app gets push token
- Client sends token to backend
- Backend stores token
- Backend event triggers notification job
- Notification job calls FCM/APNs
- Provider delivers to device
Quick recommendation
If you want the simplest implementation for most apps:
- Use Firebase Cloud Messaging
- Use your backend API to store tokens and call FCM via Firebase Admin SDK
If you want, I can show you:
- a full end-to-end example in Node.js / Python / Go, or
- how to do this specifically for iOS, Android, or web.