Subscriptions

Create or Update Subscription

Registers a new device/subscription or updates an existing one (e.g., when visiting the site again).

  • URL: /subscribe
  • Method: POST
  • Authentication: Public endpoint (Requires X-Channel-ID header instead of API Key).

Headers:

X-Channel-ID: YOUR_CHANNEL_UUID Content-Type: application/json

Body (JSON):

ParameterTypeRequiredDescription
platformstringNoTarget platform (web, android, ios). Defaults to web.
endpointstringYes*The push endpoint URL (for web) or FCM/APNS token. *Required if provider_token is missing.
provider_tokenstringYes*FCM/APNS token. *Required if endpoint is missing.
keysobjectYes (for Web)Required only if platform is web. Contains p256dh (max 255 chars) and auth (max 255 chars) strings from the browser.
attributesobjectNoCustom JSON object for metadata (max 10 keys). Key names max 50 chars, string/number values max 255 chars.

Response (200 / 201):

{ "message": "Successfully subscribed.", "subscriptionId": "123e4567-e89b-12d3-a456-426614174000" }

Examples

cURL

curl -X POST https://api.pushblitz.com/subscribe \ -H "Content-Type: application/json" \ -H "X-Channel-ID: b12f45cc-e89b-12d3-a456-426614174000" \ -d '{ "platform": "web", "endpoint": "https://fcm.googleapis.com/fcm/send/abcdef...", "keys": { "p256dh": "BBlc...", "auth": "secret..." } }'

Node.js (Fetch API)

const response = await fetch('https://api.pushblitz.com/subscribe', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Channel-ID': 'b12f45cc-e89b-12d3-a456-426614174000' }, body: JSON.stringify({ platform: 'web', endpoint: 'https://fcm.googleapis.com/fcm/send/abcdef...', keys: { p256dh: 'BBlc...', auth: 'secret...' } }) }); const data = await response.json(); console.log(data);