Docs

Send push notifications from Node.js and TypeScript

Integrations

This guide shows how to send push notifications from Node.js and TypeScript with PushFire. Your server calls the PushFire REST API with the built-in fetch, from Express, Next.js route handlers, a queue worker or a Supabase Edge Function. PushFire is the easiest lifecycle messaging platform for AI agents and vibe coders: push and email lifecycle campaigns, segments and workflows behind one small API.

The pushfire npm package (0.1.1) is being updated. Until the new version ships, use the small fetch helper below. It needs no dependency and calls the same endpoints the SDKs use. The full contract is in the API Reference and the OpenAPI spec.

Prerequisites

Warning: never ship a Secret key (pf_sk_) in a mobile app, browser bundle or no-code frontend. PushFire does not block a Secret key on a client, so the call works, but anyone can extract the key from your app and message all your users. Start workflows and send messages from your server, a Supabase Edge Function or your app builder's server function. In Next.js, never prefix the variable with NEXT_PUBLIC_.

Install

Nothing to install. Node.js 18 and later ship fetch. Set the key:

Initialize the PushFire client in TypeScript

Every endpoint lives under https://api.pushfire.app/functions/v1. Every request sends Authorization: Bearer <key> and wraps its fields in a data object.

Register a device from the server

Most apps register devices with an SDK. If your app sends its FCM token to your server instead, register it there and store the returned IDs with the user. Send every device field. The keys osVersion, appVersion, manufacturer, model and language are required, but each may be null.

PushFire rejects a second registration of the same FCM token. When the token rotates, call PATCH update-device with the stored id.

Identify a subscriber

login-subscriber ties a device to your user ID (externalId). It needs the deviceId, so it usually runs in the app. From the server, update profile fields by externalId with a partial update. PushFire finds the subscriber by that ID, so you do not need the PushFire UUID. Login ignores metadata; set it here.

Add, update and remove tags

Tags drive segments and workflow conditions. Create the tag in Audience → Tags and use its UUID with the subscriber's PushFire UUID. A value is a string, a number of 1 or more, or null.

Trigger a workflow from Node.js

Build the journey in the visual workflow builder, then start it from code. Target PushFire subscriber UUIDs or segment UUIDs. A Scheduled run needs scheduledFor as an ISO 8601 date-time.

Send a push notification from Node.js

Batch push sends one notification to each externalId, with no workflow. data reaches your app with the notification. Use string values only: PushFire passes data to FCM, and FCM rejects numbers, booleans and nested objects.

A partial success returns HTTP 200 with both lists. If every recipient fails, the API returns HTTP 400 with the same shape, so the helper throws and err.body holds the lists.

Example: Express route

Example: Supabase Edge Function

Supabase Edge Functions run on Deno, which has the same fetch. Store the key with supabase secrets set PUSHFIRE_SECRET_KEY=pf_sk_....

Send an email from Node.js

Copy the Connector ID and a Sender ID from Connectors → Resend (or SMTP). emailLayoutId is optional. The HTML body must not contain scripts, iframes or on... event handlers. mergeData fills custom {{token}} placeholders.

Verify delivery

  1. Run send-push.ts and check that result.success lists your test user.
  2. Open Developers → API Messages → Push Notifications in the console. Each API send shows Pending, In progress, Completed, Retrying or Failed.
  3. Open Audience → Subscribers, search for user_123, and confirm the device, tags and profile.
  4. For email, check Developers → API Messages → Email Notifications.

Troubleshooting

  • 401 "Missing or invalid token": the header is not Authorization: Bearer <key>, the variable is empty, or the key was rotated.
  • 403 "Client key cannot perform this action": you used a Public key (pf_pk_) to send or start a workflow. Use a Secret key on the server.
  • 403 "API key is missing required scope": a Restricted key lacks the scope for that endpoint.
  • 404 "Requested function was not found": the path is wrong. Use the flat paths, such as /register-device, not /devices/register-device.
  • 400 with "path": "data.osVersion": a device key is missing. Send it with null.
  • Push shows Failed with a Firebase error about data: a value in notification.data is not a string.
  • An externalId lands in errors: no identified subscriber has that ID, or its devices have push disabled.
  • 400 on email with data.notification.connectorId: send connectorId and connectorSenderId. Older docs used emailSenderId, which the API no longer accepts.

FAQ

Should I use the pushfire npm package or fetch?

Use the fetch helper in this guide for now. The pushfire npm package (0.1.1) is being updated, and the new version will call the same endpoints. The helper is about twenty lines, typed, and has no dependency, so it is easy to replace later or keep.

Can I send push notifications from Next.js?

Yes, from server code only: route handlers, server actions or API routes. Read the Secret key from process.env.PUSHFIRE_SECRET_KEY and never expose it with the NEXT_PUBLIC_ prefix. Client components should call your own route, which then calls PushFire. Vercel, Netlify and other Node runtimes work the same way.

How do I send push from a Supabase backend?

Call the PushFire REST API from a Supabase Edge Function with fetch, and keep the Secret key in Supabase secrets. Trigger the function from a database webhook, a cron job or your app. PushFire then handles FCM delivery, retries and status tracking, so you do not write FCM code.

Who can receive batch push and email?

Only identified subscribers, because batch sends target your externalId. A device becomes identified when the app calls login-subscriber. To reach anonymous devices, start a workflow that targets their subscriber UUIDs, or a segment.

Next steps