### Example HTTP Request for View Player
Source: https://documentation.onesignal.com/reference/view-device
Demonstrates how to make an HTTP GET request to retrieve a specific player's data. Ensure you replace placeholders with your actual app ID, player ID, and API key.
```http
GET /api/v1/players/player_id_string?app_id=your_app_id HTTP/1.1
Host: onesignal.com
Authorization: Basic YOUR_LEGACY_REST_API_KEY
```
--------------------------------
### Service Unavailable Example
Source: https://documentation.onesignal.com/reference/create-template
This example demonstrates a 'Service Unavailable' (503) response, suggesting a temporary issue. The 'Retry-After' header may be present to guide retry attempts.
```json
{
"errors": [
"Service temporarily unavailable"
]
}
```
--------------------------------
### Template Resource Content Example
Source: https://documentation.onesignal.com/reference/create-template
An example of the content structure for a template resource, showing fields for different channels.
```json
{
"isEdge": true,
"headings": {
"en": "hello from the api!"
},
"subtitle": null,
"contents": {
"en": "why hello there!"
},
"global_image": null,
"url": "https://example.com",
"isEmail": null,
"email_body": null,
"email_subject": null,
"email_preheader": null,
"isSMS": null,
"sms_from": null,
"sms_media_urls": null,
"email_reply_to_address": null,
"disable_email_click_tracking": null
}
```
--------------------------------
### Example Request to Edit Player
Source: https://documentation.onesignal.com/reference/edit-device
This example demonstrates how to send a PUT request to update a player's information, including custom tags, language, timezone, and device OS. Ensure you replace placeholders with your actual data.
```json
PUT /api/v1/players/player_id_string HTTP/1.1
Host: onesignal.com
Authorization: Basic YOUR_REST_API_KEY
Content-Type: application/json
{
"app_id": "your_app_id",
"external_user_id": "user123",
"tags": {
"level": "20",
"subscription": "active"
},
"language": "fr",
"timezone": 3600,
"device_os": "16.0"
}
```
--------------------------------
### Example HTTP Request for Viewing Players
Source: https://documentation.onesignal.com/reference/view-devices
This snippet shows how to make an HTTP GET request to the View Players API endpoint. Ensure you replace placeholders with your actual app ID and legacy API key. This is a legacy API.
```http
GET /api/v1/players?app_id=your_app_id&limit=100&offset=0 HTTP/1.1
Host: onesignal.com
Authorization: Basic YOUR_LEGACY_REST_API_KEY
```
--------------------------------
### Start Live Activity
Source: https://documentation.onesignal.com/reference/start-live-activity
Initiates a Live Activity for a user's app. This endpoint allows you to send the initial data payload to start a Live Activity, which will then be displayed on the user's device.
```APIDOC
## POST /api/v1/activity/live
### Description
Starts a Live Activity for a user's app.
### Method
POST
### Endpoint
/api/v1/activity/live
### Parameters
#### Request Body
- **activity_token** (string) - Required - The token for the Live Activity.
- **activity_state** (integer) - Optional - The state of the Live Activity. Defaults to `ActivityState.stale`.
- **priority** (integer) - Optional - The priority of the message. `10` for High, `5` for Normal. Defaults to `5`.
- **ios_sound** (string) - Optional - The name of a sound file in your app bundle to play. Use `"nil"` to silence.
- **ios_relevance_score** (number) - Optional - A value between `0` and `1` to determine the Live Activity's prominence.
- **idempotency_key** (string) - Optional - A unique identifier to prevent duplicate requests. Valid for 30 days.
### Response
#### Success Response (201)
- **notification_id** (string) - The ID of the Live Activity that was created.
#### Headers
- **Idempotent-Replayed** (boolean) - Present and set to `true` if this is a replay of a previous request with the same `idempotency_key`.
#### Error Response (400)
- **errors** (array) - Reason for the message not being started.
#### Error Response (429)
- **errors** (array) - API rate limit exceeded.
- **Retry-After** (integer) - Number of seconds to wait before retrying.
#### Error Response (503)
- Service temporarily unavailable. Retry after a short backoff.
```
--------------------------------
### Unprocessable Entity (Text Plain) Example
Source: https://documentation.onesignal.com/reference/create-template
This example illustrates an 'Unprocessable Entity' response, typically returned when no content is available for saving or when creating a push template incorrectly.
```html
The change you wanted was rejected (422)
```
--------------------------------
### Add Player Request Example
Source: https://documentation.onesignal.com/reference/add-a-device
This snippet shows a complete JSON request to register a new player with various parameters.
```json
POST /api/v1/players HTTP/1.1
Host: onesignal.com
Authorization: Basic YOUR_REST_API_KEY
Content-Type: application/json
{
"app_id": "your_app_id",
"device_type": 1,
"identifier": "abcdef123456",
"language": "en",
"timezone": -28800,
"game_version": "1.0",
"device_model": "Pixel 4",
"device_os": "12",
"ad_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"sdk": "050401",
"session_count": 5,
"tags": {
"user_type": "free",
"level": "10"
},
"external_user_id": "user123",
"notification_types": 1
}
```
--------------------------------
### Simple Retry Logic Example
Source: https://documentation.onesignal.com/reference/rate-limits
This example demonstrates a basic retry loop for API requests, including checks for success, specific error codes like 429, and a maximum attempt limit. It highlights the use of an idempotency key.
```text
attempt = 1
max_attempts = 3
send request with idempotency_key
if response is success:
stop
if response is 429:
wait Retry-After seconds
elif response is 5xx or timeout:
wait 100 seconds
if attempt < max_attempts:
retry with same idempotency_key
else:
fail safely
```
--------------------------------
### Start Live Activity
Source: https://documentation.onesignal.com/reference/start-live-activity
Initiates a Live Activity with specified event details and content. The `activity_id` is crucial for future updates.
```APIDOC
## POST /api/v1/notifications
### Description
Starts a Live Activity. This endpoint is used to initiate a Live Activity session on user devices.
### Method
POST
### Endpoint
/api/v1/notifications
### Parameters
#### Request Body
- **event** (string) - Required - The action to perform on the Live Activity. Only `start` is supported.
- **activity_id** (string) - Required - An identifier to uniquely identify the Live Activity and associated devices. This is required for updating the Live Activity later.
- **event_attributes** (object) - Required - Static data to initialize the Live Activity. Must conform to the structure defined in Live Activities developer setup.
- **contents** (object) - Required - The push message body with language-specific values. Must include an `en` property for English.
- **en** (string) - Required - The message content in English.
- **headings** (object) - Optional - The push title with language-specific values. Must include an `en` property if provided.
- **en** (string) - Required - The title in English.
- **stale_date** (integer) - Optional - A Unix timestamp (in seconds) indicating when the Live Activity becomes outdated.
- **filters** (array) - Optional - Dynamically target users based on properties like tags, activity, or location. Limited to 200 entries. Not compatible with other targeting parameters.
- **field** (string) - Required - The name of the filter to use.
- **relation** (string) - Required - The comparison operator for the filter.
- **value** (string) - Required - The value to filter by.
- **key** (string) - Optional - Used with the `tag` filter to specify the tag key.
### Request Example
```json
{
"event": "start",
"activity_id": "YOUR_UNIQUE_ACTIVITY_ID",
"event_attributes": {
"orderId": "12345",
"estimatedDelivery": "2023-10-27T10:00:00Z"
},
"contents": {
"en": "Your order is on its way!"
},
"headings": {
"en": "Order Status"
},
"stale_date": 1698397200
}
```
### Response
#### Success Response (200)
- **id** (string) - The unique ID of the notification sent.
- **recipients** (integer) - The number of devices the notification was sent to.
- **external_id** (string) - The ID you provided in the `external_id` field if you used it.
#### Response Example
```json
{
"id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"recipients": 1,
"external_id": null
}
```
```
--------------------------------
### Start Live Activity API Endpoint
Source: https://documentation.onesignal.com/reference/start-live-activity
This OpenAPI definition outlines the endpoint for starting a Live Activity. It specifies the HTTP method, path parameters, headers, and the request body structure required to send dynamic content to iOS Live Activities.
```yaml
POST /apps/{app_id}/activities/activity/{activity_type}
openapi: 3.1.0
info:
title: api.onesignal.com
version: '11.6'
servers:
- url: https://api.onesignal.com
security:
- {}
paths:
/apps/{app_id}/activities/activity/{activity_type}:
post:
summary: Start Live Activity
description: >-
Remotely start a Live Activity on iOS devices via OneSignal's REST API.
Define the activity type, target users, and send dynamic, updatable
content directly to a Live Activity interface.
operationId: start-live-activity
parameters:
- name: app_id
in: path
description: >-
Your OneSignal App ID in UUID v4 format. See [Keys &
IDs](/docs/en/keys-and-ids).
schema:
type: string
required: true
- name: Authorization
in: header
description: >-
Your App API key with prefix `Key `. See [Keys &
IDs](/docs/en/keys-and-ids).
required: true
schema:
type: string
default: Key YOUR_APP_API_KEY
- name: activity_type
in: path
description: >-
The name of the Live Activity defined in your app. This should match
the `your-nameAttributes` struct used in your app code. See [Live
Activities developer setup](/docs/live-activities-developer-setup).
Example: If your app defines a Live Activity as
`OneSignalWidgetAttributes`, then `activity_type` should be
`OneSignalWidgetAttributes`.
schema:
type: string
required: true
requestBody:
content:
application/json:
schema:
type: object
required:
- event
- activity_id
- name
- event_attributes
- event_updates
- contents
- headings
properties:
include_aliases:
type: object
description: >-
Target up to 20,000 users by their `external_id`,
`onesignal_id`, or your own custom alias. Use with
`target_channel` to control the delivery channel. Not
compatible with any other targeting parameters like
`filters`, `include_subscription_ids`, `included_segments`,
or `excluded_segments`. See [Sending messages with the
OneSignal API](/reference/create-message#include-aliases).
format: json
properties:
external_id:
description: >-
An array of external IDs which should be the same as the
user ID in your app. This is the recommended method for
targeting users. See [Users](/docs/users).
type: array
items:
type: string
include_subscription_ids:
type: array
description: >-
Target users' specific [subscriptions](/docs/subscriptions)
by ID. Include up to 20,000 `subscription_id` per API call.
Not compatible with any other targeting parameters like
`filters`, `include_aliases`, `included_segments`, or
`excluded_segments`. See [Sending messages with the
OneSignal API](/reference/create-message).
items:
type: string
included_segments:
type: array
description: >-
Target predefined [Segments](/docs/segmentation). Users that
are in multiple segments will only be sent the message once.
Can be combined with `excluded_segments`. Not compatible
with any other targeting parameters like `filters`,
`include_aliases`, or `include_subscription_ids`. See
[Sending messages with the OneSignal
API](/reference/create-message).
items:
type: string
excluded_segments:
type: array
description: >-
Exclude users in predefined [Segments](/docs/segmentation).
Overrides membership in any segment specified in the
`included_segments`. Not compatible with any other targeting
parameters like `filters`, `include_aliases`, or
`include_subscription_ids`. See [Sending messages with the
OneSignal API](/reference/create-message).
items:
type: string
```
--------------------------------
### Bad Request (Email) Example
Source: https://documentation.onesignal.com/reference/create-template
This example shows a 'Bad Request' response when creating an email template without a provided email body.
```json
// returned if isEmail:true, but there is no email body
// content available in the request.
{
"success": false,
"errors": [
"'message' Email body can not be blank"
]
}
```
--------------------------------
### AND Logic Example (Explicit)
Source: https://documentation.onesignal.com/reference/create-message
Demonstrates the explicit use of the AND operator for clarity, though it's not required.
```json
"filters": [
{"field": "tag", "key": "level", "relation": "=", "value": "10"},
{"operator": "AND"},
{"field": "session_count", "relation": ">", "value": "1"}
]
```
--------------------------------
### Example JSON Response for Viewing Players
Source: https://documentation.onesignal.com/reference/view-devices
This is an example of the JSON response structure when successfully retrieving player records. It includes total count, pagination details, and a list of player objects, each with their unique ID, identifier, tags, and other relevant information. Note that this API is legacy.
```json
{
"total_count": 6,
"offset": 0,
"limit": 300,
"players": [
{
"id": "player_id_1",
"identifier": "push_token_or_email",
"session_count": 3,
"language": "en",
"timezone": -28800,
"game_version": "1.0",
"device_os": "15.0",
"device_type": 1,
"tags": {
"level": "15",
"user_type": "free"
},
"last_active": 1625253300,
"created_at": 1625249800,
"invalid_identifier": false,
"external_user_id": "user123"
}
]
}
```
--------------------------------
### Add Player Response Example
Source: https://documentation.onesignal.com/reference/add-a-device
This snippet shows a typical JSON response upon successfully adding a player, containing the new subscription ID.
```json
{
"id": "Subscription_id_string"
}
```
--------------------------------
### OR Logic Example
Source: https://documentation.onesignal.com/reference/create-message
Users can satisfy either filter to be included. This is useful for creating broader audiences.
```json
"filters": [
{"field": "tag", "key": "level", "relation": "=", "value": "10"},
{"operator": "OR"},
{"field": "tag", "key": "level", "relation": "=", "value": "20"}
]
```
--------------------------------
### Start Live Activity
Source: https://documentation.onesignal.com/reference/start-live-activity
Remotely start a Live Activity on iOS devices via OneSignal's REST API. Define the activity type, target users, and send dynamic, updatable content directly to a Live Activity interface.
```APIDOC
## POST /apps/{app_id}/activities/activity/{activity_type}
### Description
Remotely start a Live Activity on iOS devices via OneSignal's REST API. Define the activity type, target users, and send dynamic, updatable content directly to a Live Activity interface.
### Method
POST
### Endpoint
/apps/{app_id}/activities/activity/{activity_type}
### Parameters
#### Path Parameters
- **app_id** (string) - Required - Your OneSignal App ID in UUID v4 format.
- **activity_type** (string) - Required - The name of the Live Activity defined in your app. This should match the `your-nameAttributes` struct used in your app code.
#### Header Parameters
- **Authorization** (string) - Required - Your App API key with prefix `Key `.
#### Request Body
- **event** (object) - Required
- **activity_id** (string) - Required
- **name** (string) - Required
- **event_attributes** (object) - Required
- **event_updates** (object) - Required
- **contents** (object) - Required
- **headings** (object) - Required
- **include_aliases** (object) - Optional - Target up to 20,000 users by their `external_id`, `onesignal_id`, or your own custom alias. Use with `target_channel` to control the delivery channel. Not compatible with any other targeting parameters like `filters`, `include_subscription_ids`, `included_segments`, or `excluded_segments`.
- **external_id** (array of strings) - Optional - An array of external IDs which should be the same as the user ID in your app.
- **include_subscription_ids** (array of strings) - Optional - Target users' specific subscriptions by ID. Include up to 20,000 `subscription_id` per API call. Not compatible with any other targeting parameters.
- **included_segments** (array of strings) - Optional - Target predefined Segments. Users that are in multiple segments will only be sent the message once. Can be combined with `excluded_segments`. Not compatible with any other targeting parameters.
- **excluded_segments** (array of strings) - Optional - Exclude users in predefined Segments. Overrides membership in any segment specified in the `included_segments`. Not compatible with any other targeting parameters.
```
--------------------------------
### Get Segment Details with AND/OR Operators
Source: https://documentation.onesignal.com/reference/view-segment
Retrieve segment details including subscriber count and complex filters using AND/OR operators. This example shows how to combine multiple filter conditions.
```json
{
"subscriber_count": 5678,
"payload": {
"id": "5525d515-67b4-22fe-0c7b-1353bd231113",
"name": "Engaged Users",
"description": "YOUR_SEGMENT_DESCRIPTION",
"created_at": 1658584650,
"source": "custom",
"filters": [
{"field": "session_count", "relation": ">", "value": "2"},
{"operator": "AND"},
{"field": "tag", "key": "level", "relation": "=", "value": "10"},
{"operator": "OR"},
{"field": "last_session", "relation": "<", "hours_ago": "24"}
]
}
}
```
--------------------------------
### BasicErrorResponse Schema Example
Source: https://documentation.onesignal.com/reference/csv-export
An example of the BasicErrorResponse schema, illustrating the structure of error messages and optional fields.
```json
{
"errors": [
"Service temporarily unavailable"
]
}
```
--------------------------------
### Create an app
Source: https://documentation.onesignal.com/reference/rest-api-overview
Registers a new app with platform credentials.
```APIDOC
## POST /reference/create-an-app
### Description
Registers a new app with platform credentials.
### Method
POST
### Endpoint
/reference/create-an-app
```
--------------------------------
### Start Live Activity
Source: https://documentation.onesignal.com/reference/start-live-activity
Initiates a Live Activity on iOS devices. This involves defining the activity type, selecting a target audience, setting a unique activity ID, initializing with static data via `event_attributes`, and preparing for dynamic updates using `event_updates`.
```APIDOC
## POST /api/v1/live-activities/start
### Description
Remotely start a Live Activity on iOS devices. This endpoint allows you to define the activity type, target users, and send dynamic, updatable content directly to a Live Activity interface.
### Method
POST
### Endpoint
/api/v1/live-activities/start
### Parameters
#### Request Body
- **activity_type** (string) - Required - Specifies the type of the Live Activity UI to use.
- **activity_id** (string) - Required - A unique identifier for the Live Activity (e.g., UUID, CUID, NanoID). Crucial for tracking and management.
- **event_attributes** (object) - Required - Initializes the Live Activity with static data. The structure depends on your Live Activity implementation.
- **awayTeam** (string) - Example - Name of the away team.
- **homeTeam** (string) - Example - Name of the home team.
- **event_updates** (object) - Optional - Used to update the Live Activity with dynamic content. Must conform to the `ContentState` interface defined in your app.
- **quarter** (integer) - Example - Current quarter of the game.
- **homeScore** (integer) - Example - Current score for the home team.
- **awayScore** (integer) - Example - Current score for the away team.
- **inTimeout** (boolean) - Example - Indicates if a team is in a timeout.
### Targeting Options
One of the following targeting methods must be specified:
- **Aliases & Subscription IDs**: Target specific users using identifiers like External ID, OneSignal ID, custom alias, or subscription ID.
- **Segments**: Target predefined user groups.
- **Filters**: Create custom targeting rules based on user properties.
### Request Example
```json
{
"activity_type": "sports_game",
"activity_id": "217aae2b-42ee-4097-bc3f-b7a6e9d15b9b",
"event_attributes": {
"awayTeam": "Away Team Name",
"homeTeam": "Home Team Name"
},
"event_updates": {
"quarter": 1,
"homeScore": 70,
"awayScore": 78,
"inTimeout": false
},
"filters": [
{
"field": "tag",
"key": "user_id",
"relation": "=",
"value": "specific_user_123"
}
]
}
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the Live Activity was started successfully.
- **activity_id** (string) - The ID of the started Live Activity.
#### Response Example
```json
{
"success": true,
"activity_id": "217aae2b-42ee-4097-bc3f-b7a6e9d15b9b"
}
```
```
--------------------------------
### Initialize Live Activity with Event Attributes
Source: https://documentation.onesignal.com/reference/start-live-activity
Provide static data to populate the Live Activity when it starts. The structure must match your app's defined attributes.
```json
{
"event_attributes": {
"awayTeam": "Away Team Name",
"homeTeam": "Home Team Name"
}
}
```
--------------------------------
### Rate Limit Exceeded Example
Source: https://documentation.onesignal.com/reference/create-template
An example of a 'Too Many Requests' (429) response, indicating that the API rate limit has been exceeded. The 'Retry-After' header specifies the waiting period.
```json
{
"errors": [
"API rate limit exceeded"
]
}
```
--------------------------------
### View single app
Source: https://documentation.onesignal.com/reference/rest-api-overview
Retrieves configuration and details for one app.
```APIDOC
## GET /reference/view-an-app
### Description
Retrieves configuration and details for one app.
### Method
GET
### Endpoint
/reference/view-an-app
```
--------------------------------
### AND Logic Example (Implicit)
Source: https://documentation.onesignal.com/reference/create-message
Users must satisfy both filters to be included. The AND operator is not required.
```json
"filters": [
{"field": "tag", "key": "level", "relation": "=", "value": "10"},
{"field": "session_count", "relation": ">", "value": "1"}
]
```
--------------------------------
### Example JSON Response for View Player
Source: https://documentation.onesignal.com/reference/view-device
Shows the structure of a successful JSON response when retrieving player data. This includes player ID, identifier, session count, device information, tags, and timestamps.
```json
{
"id": "player_id_string",
"identifier": "push_token_or_email",
"session_count": 5,
"language": "en",
"timezone": -28800,
"game_version": "1.0",
"device_os": "14.4",
"device_type": 1,
"tags": {
"level": "10",
"user_type": "free"
},
"last_active": 1625253300,
"created_at": 1625249800,
"invalid_identifier": false,
"external_user_id": "user123"
}
```
--------------------------------
### Create user
Source: https://documentation.onesignal.com/reference/rest-api-overview
Creates a user with optional aliases and subscriptions.
```APIDOC
## POST /reference/create-user
### Description
Creates a user with optional aliases and subscriptions.
### Method
POST
### Endpoint
/reference/create-user
```
--------------------------------
### Bad Request (Invalid Channel)
Source: https://documentation.onesignal.com/reference/view-templates
This example shows a bad request error when an invalid channel is specified.
```json
{
"errors": [
"Invalid channel"
]
}
```
--------------------------------
### Bad Request (Invalid Limit)
Source: https://documentation.onesignal.com/reference/view-templates
This example shows a bad request error when an invalid limit parameter is provided.
```json
{
"errors": [
"Invalid limit, must be within 1 to 50"
]
}
```
--------------------------------
### GET /api/v1/players
Source: https://documentation.onesignal.com/reference/view-devices
Retrieves up to 80,000 player records (Subscriptions) registered to a specific OneSignal app. This is a Legacy API.
```APIDOC
## GET /api/v1/players
### Description
Retrieve up to 80,000 player records (Subscriptions) registered to a specific OneSignal app.
This is a Legacy API. Use [View User](/reference/view-user) or [CSV Export API](/reference/csv-export) instead.
### Method
GET
### Endpoint
`https://onesignal.com/api/v1/players?app_id={app_id}&limit={limit}&offset={offset}`
### Parameters
#### Query Parameters
- **app_id** (string) - Required - Your OneSignal App ID.
- **limit** (int) - Optional - Number of entries to return (max 300, default is 300).
- **offset** (int) - Optional - Result offset for pagination.
#### Headers
- **Authorization** (string) - Required - Your OneSignal Legacy REST API Key. Value should be `Basic YOUR_LEGACY_REST_API_KEY`.
### Request Example
```http
GET /api/v1/players?app_id=your_app_id&limit=100&offset=0 HTTP/1.1
Host: onesignal.com
Authorization: Basic YOUR_LEGACY_REST_API_KEY
```
### Response
#### Success Response (200)
- **total_count** (integer) - Total number of devices for the app.
- **offset** (integer) - Current pagination offset.
- **limit** (integer) - Number of devices returned in this response.
- **players** (array) - List of device objects.
- **players[].id** (string) - Unique OneSignal player ID.
- **players[].identifier** (string) - Push token, email, or phone number.
- **players[].tags** (object) - Custom tags set on the device.
- **players[].external_user_id** (string) - Your internal user ID.
#### Response Example
```json
{
"total_count": 6,
"offset": 0,
"limit": 300,
"players": [
{
"id": "player_id_1",
"identifier": "push_token_or_email",
"session_count": 3,
"language": "en",
"timezone": -28800,
"game_version": "1.0",
"device_os": "15.0",
"device_type": 1,
"tags": {
"level": "15",
"user_type": "free"
},
"last_active": 1625253300,
"created_at": 1625249800,
"invalid_identifier": false,
"external_user_id": "user123"
}
]
}
```
### Errors
- 400 Bad Request – Invalid query parameters.
- 401 Unauthorized – Invalid or missing API key.
- 403 Forbidden – Access not allowed for this app or key.
```