> For the complete documentation index, see [llms.txt](https://docs.contextsdk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.contextsdk.com/context-push/push-notification-providers/onesignal.md).

# OneSignal

## Integrating ContextSDK Push Notifications with OneSignal Journeys

This guide provides step-by-step instructions on how to configure [OneSignal's Journeys](https://documentation.onesignal.com/docs/journeys-overview) to send push notifications using a webhook to interact with the ContextPush API.

### Step 1: Add a Webhook Action to the Journey

1. Go to the **Journey** you want to leverage context-aware push notifications.
2. **Add a new action** within your journey by selecting "Add Action" and then choose "Send Webhook."
3. **Configure the webhook** with the following details:
   * **URL**: `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user`
   * **Request Type**: `POST`

### Step 2: Set Up Request Headers

In the webhook configuration, include the necessary headers to authenticate the request:

* **Authorization**: `Token [Your_Token]`
* **Content-Type**: `application/json`

<figure><img src="/files/grvsGloSbwHeO6yH9I2E" alt="" width="375"><figcaption></figcaption></figure>

### Step 3: Define the Request Body

Configure the webhook payload using OneSignal's templating to dynamically include user-specific data. Use the following JSON structure:

```json
{
  "bundle_id": "com.contextsdk.demo",
  "platform": "ios",
  "user_id": "{{ user.external_id }}",
  "content": {
    "title": "It's time to get started with crypto",
    "body": "Just upload your ID, and start trading now"
  },
  "deliver_within_hours": 6,
  "campaign_id": "daily-reminder",
  "delivery_method": "context_aware"
}
```

**Notes:**

* Replace `{{ user.external_id }}` with the appropriate OneSignal variable for the user ID.
* Adjust the `title` and `body` fields to match your campaign's messaging.

#### Using the Key/Value Pairs Body

If you prefer configuring your payload purely through the OneSignal UI we have a special endpoint that is compatible with a non nested JSON body. Instead of `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user` use the `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user_flattened` endpoint. This allows you to replace all nested values with keys in the format of `content/title`, `content/body`, etc.

This way you can fully configure ContextPush using only Key/Value pairs.

```json
{
  "bundle_id": "com.contextsdk.demo",
  "platform": "ios",
  "user_id": "{{ user.external_id }}",
  "content/title": "It's time to get started with crypto",
  "content/body": "Just upload your ID, and start trading now",
  "deliver_within_hours": 6,
  "campaign_id": "daily-reminder",
  "delivery_method": "context_aware"
}
```

<figure><img src="/files/upkLGTbRwHJa9q6kDqar" alt="" width="375"><figcaption></figcaption></figure>

#### Localization

You can use the built-in Liquid syntax to directly supply the localized string when scehduling a message. The below example uses the `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user_flattened` endpoint:

```json
{%- assign userLang = user.language -%}
{
  "bundle_id": "com.contextsdk.internal",
  "platform": "ios",
  "user_id": "{{ user.external_id }}",
  "content/default_locale": "en",
  "content/title/en": "{% if userLang == 'de' -%} James, es ist Zeit für deinen Englischkurs! {%- else -%} James, it's time for your english course! {%- endif %}",
  "content/body/en": "{% if userLang == 'de' -%} Starte jetzt mit deinem Kurs! {%- else -%} Start course now because its a good time! {%- endif %}",
  "deliver_within_hours": 3,
  "campaign_id": "daily-reminder",
  "delivery_method": "context_aware"
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.contextsdk.com/context-push/push-notification-providers/onesignal.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
