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.

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.

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.