# OneSignal

OneSignal is a customer engagement platform for push notifications, email, SMS, and in-app messaging. The Sling OneSignal connector extracts data from the OneSignal REST API, supporting apps, segments, templates, messages/notifications, and devices.

{% hint style="success" %}
**CLI Pro Required**: APIs require a [CLI Pro token](/sling-cli/cli-pro.md) or [Platform Plan](/sling-platform/platform.md).
{% endhint %}

## Setup

The following credentials and inputs are accepted:

**Secrets:**

* `app_api_key` **(required)** -> Your OneSignal App API Key
* `org_api_key` **(required for `apps` endpoint)** -> Your OneSignal Organization API Key

**Inputs:**

* `app_id` **(required)** -> Your OneSignal App ID
* `anchor_date` (optional) -> The starting date for historical data extraction (default: 1 year ago). Format: `YYYY-MM-DDTHH:MM:SSZ`

### Getting Your API Keys

1. Log in to your OneSignal dashboard at [dashboard.onesignal.com](https://dashboard.onesignal.com)
2. **App API Key**: Go to **Settings** > **Keys & IDs** to find your App API Key and App ID
3. **Organization API Key**: Go to **Organization** > **API Keys** and create a new key

### Using `sling conns`

{% code overflow="wrap" %}

```bash
sling conns set ONESIGNAL type=api spec=onesignal \
  secrets='{ app_api_key: your_app_api_key, org_api_key: your_org_api_key }' \
  inputs='{ app_id: your_app_id }'
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/connections/api-connections/pages/eAdVs2BHCgdr6RS8GoJC#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export ONESIGNAL='{ type: api, spec: onesignal, secrets: { app_api_key: "your_app_api_key", org_api_key: "your_org_api_key" }, inputs: { app_id: "your_app_id" } }'
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/connections/api-connections/pages/eAdVs2BHCgdr6RS8GoJC#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  ONESIGNAL:
    type: api
    spec: onesignal
    secrets:
      app_api_key: "your_app_api_key"
      org_api_key: "your_org_api_key"
    inputs:
      app_id: "your_app_id"
```

**With anchor date for historical data:**

```yaml
connections:
  ONESIGNAL:
    type: api
    spec: onesignal
    secrets:
      app_api_key: "your_app_api_key"
      org_api_key: "your_org_api_key"
    inputs:
      app_id: "your_app_id"
      anchor_date: "2024-01-01T00:00:00Z"
```

## Replication

Here's an example replication configuration to sync OneSignal data to a PostgreSQL database:

```yaml
source: ONESIGNAL
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: onesignal.{stream_name}

streams:
  # Organization data
  apps:

  # App-level reference data
  segments:
  templates:

  # Incremental event data
  messages:
    mode: incremental

  # Device/player data (deprecated API)
  devices:
```

**Sync all endpoints:**

```yaml
source: ONESIGNAL
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: onesignal.{stream_name}

streams:
  '*':
```

## Endpoints

| Endpoint    | Description                                           | Incremental |
| ----------- | ----------------------------------------------------- | ----------- |
| `apps`      | All apps in the organization (requires `org_api_key`) | No          |
| `segments`  | All segments for the app                              | No          |
| `templates` | All message templates for the app                     | No          |
| `messages`  | Sent messages/notifications, filtered by time offset  | Yes         |
| `devices`   | Player/device records (deprecated API)                | No          |

To discover available endpoints:

```bash
sling conns discover ONESIGNAL
```

## Rate Limiting

The OneSignal API has a rate limit of 1 request per second for view endpoints. The connector automatically:

* Uses conservative rate limiting (1 request/second)
* Limits concurrency to 1 parallel request
* Retries with exponential backoff on 429 (rate limit) responses
* Retries on 5xx server errors

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.slingdata.io/connections/api-connections/onesignal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
