Quickstart for Event Streams

Guided walkthrough on setting up an example Event Stream

Event streams are a way to stream data out of OneSignal to your or a third-party destination. For the example in this guide, we will be sending message events to webhook.site, which is a useful tool when testing event streams because it will accept any configuration of HTTP request and display that HTTP request structure so you can see exactly how the HTTP request is working before pointing it at yours or a third-party API endpoint.

Setup

Requirements

1. Create a new Event Stream

To create a new event stream, navigate to the event streams section of the dashboard. Event streams are located under the Data -> Event Streams in the Dashboard. From there, select the "New Event Stream" button.

2. Select the Trigger

Click the “Select Events" button to add the events that should trigger the event stream.

Select Webhook Trigger

A modal will pop up asking which events you would want to trigger for the event stream. For testing, we suggest selecting "Sent" or "Received" events for the channels you have configured for your application.

3. Configure the Event Stream

Go to webhook.site. Find “Your unique URL” in the center of the page. Copy that URL.

In OneSignal, paste it into the URL field in the "Configure" step.

4. Configure the Event Stream body

The event stream body, along with the URL and the headers, accepts liquid syntax. The following is the example payload that we will use.

{
       "user_id": "{{ event.external_id }}",
       "event_id": "{{ event.id }}",
       "event": "{{ event.kind }}",
       "properties": {
         "message_id": "{{ message.id }}",
         "message_name": "{{ message.name }}",
         "message_title": "{{ message.title.en }}",
         "message_contents": "{{ message.contents.en }}",
         "template_id": "{{ message.template_id }}",
         "subscription_id": "{{ event.subscription_id }}",
         "subscription_device_type": "{{ event.subscription_device_type }}",
         "source": "onesignal"
       },
       "originalTimestamp": "{{ event.datetime }}"
  }

Enter In the Body section of the page, select "Custom Body" in the drop-down and enter liquid syntax into the Custom Body text field.

5. Save and activate

Touch the down arrow on the save button at the bottom of the screen, click the option save and exit. This will bring you back to the event streams page under settings.

Locate your event stream from the list of event streams and navigate to it by clicking on it. In the top right corner, click on the actions drop-down and select activate from the drop-down menu.

Confirm that the event stream is active.

6. Send a message (prerequisite)

Send a message from your OneSignal application. This will cause events to be triggered from the event stream you have just configured. For more information on how to send a message, please check out How to Send a Message.

7. Results

On the OneSignal Event Stream page, you can see the successful event stream sends:

Navigate back to webhook.site

On webhook.site, you can browse all of the HTTP requests triggered by the message that was just sent, along with their payload and headers.

👍

You have now successfully tested your Event Stream!