Prompt
How do I send transactional push notifications from an API?
Latest observation
Oct 14, 2026
OpenAI APIWeb search: off
To send transactional push notifications from an API, you usually do this flow:
-
Your app collects a device push token
- iOS: APNs token
- Android: FCM token
- Web: Web Push subscription/token
-
Your backend stores that token
- Tie it to a user/account/device.
-
When an event happens
- e.g. password reset, order shipped, payment failed, OTP needed
-
Your backend calls a push provider API
- Common providers:
- Firebase Cloud Messaging (FCM) for Android, iOS, web
- Apple Push Notification service (APNs) for iOS directly
- Third-party services like OneSignal, Pusher Beams, Twilio Notify, AWS SNS
- Common providers:
-
Provider delivers the notification to the device
Typical API request
You send a server-to-server request with:
- recipient token(s)
- title/body
- data payload
- platform-specific options
- auth credentials
Example: Firebase Cloud Messaging (FCM)
HTTP v1 request
You send a POST request to Google’s FCM API:
POST https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
Example JSON
{
"message": {
"token": "DEVICE_FCM_TOKEN",
"notification": {
"title": "Order shipped",
"body": "Your order #12345 is on the way."
},
"data": {
"orderId": "12345",
"type": "order_shipped"
}
}
}
Authentication
Use a service account OAuth2 access token in the Authorization header:
Authorization: Bearer ACCESS_TOKEN
Example: APNs directly for iOS
Request
POST https://api.push.apple.com/3/device/DEVICE_TOKEN
Headers:
authorization: bearer JWT_TOKEN
apns-topic: com.example.app
apns-push-type: alert
Body:
{
"aps": {
"alert": {
"title": "Payment received",
"body": "We received your payment successfully."
},
"sound": "default"
},
"transactionId": "abc123"
}
APNs requires:
- Apple Developer account
- Auth key (.p8) or certificate
- JWT-based auth for production systems
If you want transactional reliability
For transactional notifications, you usually want:
- immediate delivery
- idempotency so you don’t send duplicates
- retry logic for transient failures
- token cleanup when tokens become invalid
- auditing/logging for delivery status
- fallback channels like email/SMS for critical messages
Recommended architecture
A common production setup is:
- Your app/backend
- creates event
- Notification service
- decides channel, template, locale
- Push provider
- FCM/APNs/OneSignal
- Queue
- retries and rate limiting
- Database
- stores device tokens and send history
Minimal backend pseudo-flow
def send_order_shipped(user_id, order_id):
token = get_device_token(user_id)
payload = {
"title": "Order shipped",
"body": f"Your order #{order_id} is on the way.",
"data": {"orderId": order_id, "type": "order_shipped"}
}
push_provider.send(token, payload)
Best practices
- Keep the push payload small
- Put sensitive data on the server, not in the notification body
- Use data payloads for app handling
- Handle invalid/expired tokens
- Prefer a provider SDK or official API
- Secure your API keys/service account credentials
- Use templates for consistent transactional messages
If you want, I can show you:
- a working example in Node.js / Python / PHP / Go, or
- the exact API call for FCM, APNs, or OneSignal.