API mocks

On this page

OneSignal

A mock compatible with OneSignal's REST API for push, email and SMS. Your app creates users and subscriptions and sends messages as it does with OneSignal; the mock resolves who would receive each message like OneSignal does and records every delivery, so tests can assert who got what. Nothing is delivered to devices.

Testlie is not affiliated with, endorsed by or sponsored by OneSignal. The name is a trademark of its owner, used here only to say which API this mock is compatible with.

Connect

Create a OneSignal mock under API mocks → Push & messaging. Use its base URL in place of https://api.onesignal.com (or https://onesignal.com/api/v1 for the legacy paths), its app id and its App API key, sent as Authorization: Key <key> (Basic and Bearer work too, as older SDKs send them). A wrong key answers 403; a wrong app_id answers 400 app_id not found.

js
await fetch(`${BASE}/notifications?c=push`, {
  method: "POST",
  headers: { Authorization: `Key ${process.env.ONESIGNAL_REST_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    app_id: process.env.ONESIGNAL_APP_ID,
    target_channel: "push",
    include_aliases: { external_id: ["user_1"] },
    contents: { en: "Your order shipped" },
  }),
});

Endpoints

Endpoint
POST /notifications Create a push, email or SMS message
GET /notifications/{id}?app_id= The message with its delivery stats
GET /notifications?app_id=&limit=&offset= List messages
DELETE /notifications/{id}?app_id= Cancel a scheduled message
POST /apps/{app_id}/users Create a user with aliases, properties and subscriptions
GET, PATCH, DELETE /apps/{app_id}/users/by/{alias}/{id} Read, update (tags merge) or delete a user
PATCH /apps/{app_id}/users/by/{alias}/{id}/identity Add aliases
POST /apps/{app_id}/users/by/{alias}/{id}/subscriptions Add a subscription
PATCH, DELETE /apps/{app_id}/subscriptions/{id} Update or delete a subscription
POST /players, GET /players/{id} Legacy device records

Targeting

Messages target subscriptions like on OneSignal: include_aliases (with target_channel), include_subscription_ids (or legacy include_player_ids), included_segments (Subscribed Users, Total Subscriptions, Active Users, All) or filters on tags (with {"operator": "OR"} between groups). Only enabled subscriptions of the message's channel receive it.

  • Aliases or subscriptions that cannot receive it come back in errors.invalid_aliases / errors.invalid_player_ids.
  • When nobody can receive it, the answer is 200 {"id": "", "errors": ["All included players are not subscribed"]}.
  • Push messages need English content (contents.en).
  • idempotency_key replays the first answer with an Idempotent-Replayed: true header.

Delivery

A message is delivered after send_after (if any) plus the mock's asynchronous steps delay; until then remaining counts its recipients and it can be cancelled. Then successful, failed and platform_delivery_stats fill in. Subscriptions whose token starts with invalid fail; the everything is rejected scenario fails every delivery. Each delivery is listed under Objects with the subscription, user and status.

OneSignal's event webhooks are configured per app in its dashboard and are not part of this mock.

The server error scenario answers 503 with Retry-After: 1 (the other mocks answer 500).