API Reference

Authentication, SDK method parameters, and the push payload format.

Authentication#

Every request is authenticated with a per-app API key. Send it as a Bearer token:

http
Authorization: Bearer <YOUR_APP_API_KEY>

Client SDKs take the same key as apiKey. A key only works for the app it was generated in. A 401 response means the key is missing, wrong, or belongs to a different app. See Troubleshooting.

Send a push from your server#

Send a push to specific devices from your backend, for example when an order ships. Use the App ID and an API key from the same app. Each device's subscriptionId is the value initialize() returns (also listed under Audience → Subscriptions).

bash
curl -X POST https://api.notifysphere.in/client/YOUR_APP_ID/send/notification \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "subscriptionIds": ["SUBSCRIPTION_ID"],
    "title": "Your order shipped!",
    "message": "Track it live from the app.",
    "actionButtons": [
      { "id": "track", "label": "Track order" },
      { "id": "later", "label": "Later" }
    ]
  }'
FieldTypeRequiredDescription
subscriptionIdsstring[]YesDevices to send to.
titlestringYesNotification title.
messagestringYesNotification text.
actionButtons{ id, label }[]NoOptional buttons. A tap reaches the app as an action event with the button id. Needs React Native SDK 1.3.1+ (see Action buttons).

A successful call returns { "success": true } and the push shows up under Delivery → Sent Messages with source API. A missing Authorization header returns 403; a wrong key, or a key from another app, returns 401.

Operations#

  • Register / update a user: initialize() registers the device token and profile, and returns a subscription ID.
  • Update tags: updateTags() sets key-value tags used for segments.
  • Post an event: postEvent() records a conversion and attributes it to a campaign.
  • Delivery and press tracking: sent automatically by the SDK, including from the background handler. Button taps include the button id (action_id).
  • Sessions: the SDK sends a session_id with the registration and every event. Read it with getSessionId().

initialize()#

javascript
const subscriptionId = await NotifySphere.initialize({
  applicationUserId: 123,
  type: 'AndroidPush', // or 'IOSPush'
  appId: 'your-notifysphere-app-id',
  apiKey: 'your-api-token',
  tags: { userType: 'customer' },
  debug: __DEV__,
});
FieldTypeRequiredDescription
applicationUserIdstring | numberYesYour own identifier for the user.
type'AndroidPush' | 'IOSPush'YesChannel for this device.
appIdstringYesnotifySphere App ID.
apiKeystringYesApp API key.
name / email / phonestringNoOptional profile fields.
tagsRecord<string, string>NoOptional initial tags.
debugbooleanNoEnable verbose SDK logging.

updateTags()#

javascript
await NotifySphere.updateTags({
  applicationUserId: 123,
  type: 'AndroidPush',
  tags: { plan: 'premium' },
});
FieldTypeRequiredDescription
applicationUserIdstring | numberYesThe same ID used in initialize().
typestringYesChannel type.
tagsRecord<string, string>YesTags to set or overwrite.

postEvent()#

javascript
await NotifySphere.postEvent({
  event: 'booking',
  nsClick: 'abc123', // optional, from a campaign deep-link
  data: { revenue: 2500, order_id: 'ORD123' },
});
FieldTypeRequiredDescription
eventstringYesEvent name, for example booking.
nsClickstringNoAttribution token (ns_click) from a campaign deep link.
dataobjectNoArbitrary event data such as revenue or order ID.

Push payload#

Messages sent through FCM use a mixed payload: a notification block plus a data block.

json
{
  "notification": { "title": "Hello!", "body": "You have a new message." },
  "data": {
    "notification_id": "uuid-here",
    "sound": "default",
    "imageUrl": "https://example.com/image.jpg",
    "channelId": "channel_default"
  },
  "android": { "priority": "high" }
}

Background handler#

Register setBackgroundHandler({ appId, apiKey }) synchronously before registerComponent(). It needs the apiKey too, otherwise delivery calls from a killed app return 401.

Stuck or something unclear? Contact us and we'll help.