> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-sarvam.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Streams

> Forward user actions and campaign events to your API endpoint in near real-time using MoEngage Streams.

With MoEngage Streams, you can configure your API endpoint, define the events you want to forward, and then view a stream of data flowing into your system. You can then utilize the data to enrich your data warehouses and recommendation systems.

## Use Cases for MoEngage Streams

The following are a few popular use cases for Streams:

* Enrich the central data warehouse with MoEngage events such as Notification Clicked Android, Email Clicked, SMS Clicked, and so on.
* Forward the Conversion Events, such as Purchase, Song Played, Bill Payment Done, and so on, from MoEngage to the external Analytics tool.
* Feed campaign interaction events from MoEngage to your recommendation system.
* Export the notification interaction data from MoEngage to your machine learning system for optimizing the performance of your algorithms.
* Send all user events present in MoEngage to an external data lake.

## Campaign Interaction Events

The following is a list of Campaign Interaction Events that MoEngage generates, which you will often need to be sent to your API endpoint:

| Event Name                    | Event Code                      | Channel           |
| :---------------------------- | :------------------------------ | :---------------- |
| Email Sent                    | `MOE_EMAIL_SENT`                | Email             |
| Email Deferred                | `MOE_EMAIL_DEFERRED`            | Email             |
| Email Delivered               | `MOE_EMAIL_DELIVERED`           | Email             |
| Email Dropped                 | `MOE_EMAIL_DROP`                | Email             |
| Email Bounced                 | `MOE_EMAIL_HARD_BOUNCE`         | Email             |
| Email Soft Bounced            | `MOE_EMAIL_SOFT_BOUNCE`         | Email             |
| Email Opened                  | `MOE_EMAIL_OPEN`                | Email             |
| Email Clicked                 | `MOE_EMAIL_CLICK`               | Email             |
| Email Unsubscribed            | `MOE_EMAIL_UNSUBSCRIBE`         | Email             |
| Email Spam Complained         | `MOE_EMAIL_SPAM`                | Email             |
| SMS Sent                      | `SMS_SENT`                      | SMS               |
| SMS Delivered                 | `SMS_DELIVERED`                 | SMS               |
| Notification Received Android | `NOTIFICATION_RECEIVED_MOE`     | Push              |
| Notification Clicked Android  | `NOTIFICATION_CLICKED_MOE`      | Push              |
| Notification Swiped Android   | `NOTIFICATION_CLEARED_MOE`      | Push              |
| Notification Sent iOS         | `n_i_s`                         | Push              |
| Notification Clicked iOS      | `NOTIFICATION_CLICKED_IOS_MOE`  | Push              |
| Notification Received Web     | `NOTIFICATION_RECEIVED_WEB_MOE` | Push              |
| Notification Clicked Web      | `NOTIFICATION_CLICKED_WEB_MOE`  | Push              |
| Connector Sent                | `MOE_CONNECTOR_SENT`            | Connector         |
| Card Sent                     | `MOE_CARD_SENT`                 | Cards             |
| Card Delivered                | `MOE_CARD_DELIVERED`            | Cards             |
| Card Viewed                   | `MOE_CARD_VIEWED`               | Cards             |
| Card Clicked                  | `MOE_CARD_CLICKED`              | Cards             |
| Mobile In-App Shown           | `MOE_IN_APP_SHOWN`              | Mobile In-Apps    |
| Mobile In-App Clicked         | `MOE_IN_APP_CLICKED`            | Mobile In-Apps    |
| Mobile In-App Closed          | `MOE_IN_APP_DISMISSED`          | Mobile In-Apps    |
| On-site Message Shown         | `MOE_ONSITE_MESSAGE_SHOWN`      | On-site Messaging |
| On-site Message Clicked       | `MOE_ONSITE_MESSAGE_CLICKED`    | On-site Messaging |
| On-site Message Closed        | `MOE_ONSITE_MESSAGE_DISMISSED`  | On-site Messaging |
| User Entered Flow             | `USER_ENTERED_FLOW`             | Flows             |
| User Exited Flow              | `USER_EXITED_FLOW`              | Flows             |
| User Added to Control Group   | `MOE_CAMPAIGN_CONTROL_GROUP`    | All channels      |

* With the events above, the following event attributes will be exported by default: `campaign_id`, `campaign_name`, `campaign_type`, `campaign_channel`.
* The following event attributes are not supported for export in streams currently: `email_subject`, `email_click_url`, `inapp_widget_clicked`, `onsite_message_url_clicked`.

For more information on when the campaign events and attributes are tracked, refer to [Data Exports Glossary](/user-guide/data/exports/events/data-export-glossary).

## API Request Format

When Streams sends an event to your API endpoint, the request format will be as below:

**Headers:** `"Content-Type":"application/json"`

**Request Body:**

<Tabs>
  <Tab title="JSON">
    ```json theme={null}
    {
        "app_name": "App Name",
        "source": "MOENGAGE",
        "moe_request_id": "moengage unique request id for each request",
        "events": [{
            "event_name": "Notification Received Android",
            "event_code": "NOTIFICATION_RECEIVED_MOE",
            "event_uuid": "moengage unique id for each event",
            "event_time": 1580967474,
            "event_type": "CAMPAIGN_EVENT",
            "event_source": "MOENGAGE",
            "push_id": "recipient device’s push token",
            "uid": "<MoEngage customer_id>",
            "event_attributes": {
                "campaign_id": "353df897hkbh67658",
                "campaign_name": "Name of the Campaign",
                "campaign_type": "Event Trigger",
                "campaign_channel": "Push"
            },
            "user_attributes": {
                "moengage_user_id": "moe_internal_user_id",
                "user_attr_1": "user_attr_val1",
                "user_attr_2": "user_attr_val2"
            },
            "device_attributes": {
                "moengage_device_id": "moe_internal_device_id",
                "device_attr_1": "device_attr_val1",
                "device_attr_2": "device_attr_val2"
            }
        }]
    }
    ```
  </Tab>
</Tabs>

## Streams Data Glossary

<Info>
  For the full list of updated events and attributes, refer to [Data Exports Glossary](/user-guide/data/exports/events/data-export-glossary).
</Info>

The keys in the API request and their description are:

| Key                  | Description                                                  |
| :------------------- | :----------------------------------------------------------- |
| workspace name       | Your workspace name in MoEngage.                             |
| source               | `MoEngage` to identify the requests coming from MoEngage.    |
| event\_name          | Display Name of the event as seen on the MoEngage dashboard. |
| event\_code          | Raw event code as present in the MoEngage system.            |
| event\_uuid          | Unique event identifier for de-duplication.                  |
| event\_time          | Time of event in UTC (epoch time in seconds).                |
| event\_type          | `CAMPAIGN_EVENT` or `USER_ACTION_EVENT`.                     |
| event\_source        | Source identifier (value = `MoEngage`).                      |
| push\_id             | Push token (available for Push-related events).              |
| email\_id            | Recipient email (available for Email-related events).        |
| mobile\_number       | Recipient mobile number (available for SMS-related events).  |
| uid                  | MoEngage `customer_id` unique identifier.                    |
| campaign\_name       | Campaign name in MoEngage.                                   |
| campaign\_id         | Campaign ID in MoEngage.                                     |
| event\_attributes    | Dictionary of additional event attributes.                   |
| campaign\_channel    | Channel type: Push / Email / SMS.                            |
| user\_attributes     | Dictionary of additional user properties.                    |
| moengage\_user\_id   | MoEngage internal user ID.                                   |
| device\_attributes   | Dictionary of additional device attributes.                  |
| campaign\_type       | Type: Periodic, Active, One-time.                            |
| variation\_id        | Present for campaign variations.                             |
| locale\_id           | Present for campaigns with multiple locales.                 |
| locale\_name         | Display name of the locale.                                  |
| parent\_campaign\_id | Identifier for localized campaign parents.                   |
| parent\_flow\_id     | Identifier for campaigns within a MoEngage Flow.             |
| parent\_flow\_name   | Name of the MoEngage Flow.                                   |

## Authentication Methods

Streams supports the following types of authentications:

* **No auth**
* **Basic Auth**: Streams supports the standard Basic Auth implementation. You must provide MoEngage with the username and password while configuring Streams. MoEngage always encrypts all authentication data in its systems.
* **OAuth 2.0**: Streams supports OAuth 2.0 authentication using the Client Credentials grant type, where MoEngage fetches and refreshes the access token for you. A self-serve option to select OAuth 2.0 directly in Streams is not yet available. For setup steps, refer to [Configure OAuth 2.0 for Streams](#configure-oauth-20-for-streams).

To support other authentication methods such as API Key, Bearer Token, and so on, you can communicate the same through the enablement ticket and provide MoEngage with the Header key and static value to be passed. Apart from OAuth 2.0, where MoEngage fetches and refreshes the access token through your Authorization configuration, MoEngage cannot support dynamically refreshing API keys and tokens.

## Configure OAuth 2.0 for Streams

To use OAuth 2.0 as the authentication method for Streams, first create an OAuth 2.0 configuration in MoEngage, and then request enablement for your Streams endpoint through a support ticket.

<Steps>
  <Step title="Create an OAuth 2.0 configuration">
    Navigate to **Settings** > **Advanced settings** > **Authorization configuration** and add an OAuth 2.0 configuration using the Client Credentials grant type. Provide the token endpoint, credentials, and response settings for your authorization server. For the full walkthrough, refer to [Authorization Configuration with OAuth 2.0](/user-guide/settings/advanced-settings/authorization-configuration-with-oauth-20).
  </Step>

  <Step title="Confirm the configuration is active">
    Save the configuration and verify that its status is **Active** on the Authorization configuration page. A "Failed" configuration cannot fetch a token and cannot be used for Streams.
  </Step>

  <Step title="Note the OAuth configuration ID">
    Open the OAuth 2.0 configuration you created. The configuration ID is the last segment of the page URL. For example, if the URL is `.../advanced/auth-config/edit/69242b6047c75584338719e5`, the configuration ID is `69242b6047c75584338719e5`. Copy this ID to include in the enablement ticket.

    <img src="https://mintcdn.com/moengage-sarvam/WOTDpKH4PV83vTKH/images/streams-oauth-config-full.png?fit=max&auto=format&n=WOTDpKH4PV83vTKH&q=85&s=8445471e1df7c50d4b2c36a23ec82ea9" alt="The OAuth configuration ID appears as the last segment of the Authorization configuration page URL" width="2542" height="1514" data-path="images/streams-oauth-config-full.png" />
  </Step>

  <Step title="Raise a support ticket to enable OAuth 2.0 for Streams">
    Follow the steps in [Enable Streams for Your Account](#enable-streams-for-your-account) and include the OAuth configuration ID so that the Support team can link your OAuth 2.0 configuration to your Streams endpoint.
  </Step>
</Steps>

## Enable Streams for Your Account

<Note>
  Streams is available as part of the Streams add-on. Contact your dedicated MoEngage Customer Success Manager (CSM) to enable it for your account.
</Note>

Streams can export data to your API endpoint or one of the partners integrated with MoEngage.

### Set Up Streams for Exporting Data to Your API Endpoint

To export data from MoEngage to your servers, contact your MoEngage Customer Success Manager (CSM) or the Support team with the following information:

1. API endpoint to send the data. It can be something like `https://api.example.com/events`.
2. List of events that need to be sent to this API endpoint. A list of campaign events available for export is mentioned in the [Campaign Interaction Events](#campaign-interaction-events) section.
3. List of user attributes and device attributes that need to be sent to the API endpoint with each event.
4. If you need all campaign interaction events, MoEngage exports such events as mentioned in the [Campaign Interaction Events](#campaign-interaction-events) section.

You can use the following template to raise a Streams enablement request:

<Tabs>
  <Tab title="Support Ticket">
    ```text theme={null}
    Hey!

    Please enable Streams for my Workspace.

    Workspace Region: DC-01/DC-02/DC-03/DC-04
    Workspace Name: MyWorkspace
    Workspace ID: <my-workspace-id>

    API Endpoint: [https://www.example.com/api?url_param1=vaue1](https://www.example.com/api?url_param1=vaue1)

    Headers:
    header1: value1
    header2: value2

    Authentication:
    Method: No auth/Basic Auth/OAuth 2.0
    [Only for basic auth] Basic Auth username: "Username"
    [Only for basic auth] Basic Auth password: "Password"
    [Only for OAuth 2.0] OAuth configuration ID: "<oauth-config-id>"

    Events to export: All/List of events
    [Optional] List of events: List of events to export

    User properties to export: All/List of user properties
    [Optional] List of user properties: List of user properties to export
    ```
  </Tab>
</Tabs>

<Info>
  **Whitelist IPs**

  If your endpoints are in a Virtual Private Cloud (VPC) or not accessible publicly, you must whitelist [these](/user-guide/settings/account/security/ip-whitelisting-in-moengage) MoEngage IPs depending on the region of your Workspace.
</Info>

### Set Up Streams for Exporting Data to Partners

With Streams, you can export data directly to integrated partners so that you can enrich your marketing/analytics activities on these platforms. As of now, Streams can export data to the following partners:

* [Mixpanel](https://partners.moengage.com/hc/en-us/articles/4410027746836-Mixpanel#01FV1SH74TEQEBE0JVVAWJSWAS)
* [Amplitude](https://partners.moengage.com/hc/en-us/articles/4409507678228-Amplitude-Audiences#h_01HJ11HMQGHRZT4GR260D27QK3)
* [Segment](https://partners.moengage.com/hc/en-us/articles/12661517099284-MoEngage-Source)
* [mParticle](https://partners.moengage.com/hc/en-us/articles/10223363585428-mParticle-Inbound)
* [Rudderstack](https://partners.moengage.com/hc/en-us/articles/12718141249556-MoEngage-Source)

Please follow partner-specific integration documents for setting this up.

## Stream Events to Another MoEngage App

With MoEngage Streams, you can sync events from one MoEngage App to another. Common use cases include:

* **Cross-Product Promotions**: If you have teams across various product offerings, keeping two apps synced helps you cross-promote products to upsell and increase conversion.
* **Centralized Analysis**: Businesses with multiple apps can run cross-app analysis to unlock higher LTV, cross-sell, and increase brand loyalty.

To set this up:

<Steps>
  <Step title="Get your Streams endpoint">
    Speak to your CSM to get your dedicated Streams endpoint for your destination app.
  </Step>

  <Step title="Set up Streams on the source app">
    Follow the [enablement steps](#enable-streams-for-your-account) to configure the source app with the following details:

    * **Endpoint:** Use the dedicated MoEngage endpoint provided for your destination app.
    * **Authentication:** Enable Basic Auth. Use your destination app's **Workspace ID** as the username and its **Data API Key** as the password.
    * **Header:** Provide `"Content-Type" : "application/json"`.
    * **Events/Properties:** Select the list of events and user properties you want to stream.
  </Step>
</Steps>

## Limitations

Please be aware of the following constraints or limitations while integrating Streams with third-party apps.

* MoEngage can send data to only one static endpoint. If the access token expires, use an OAuth 2.0 configuration so that MoEngage can fetch and refresh the token for you (see [Authentication Methods](#authentication-methods)). For any other authentication method, MoEngage cannot integrate with an endpoint where the access token or link expires or is refreshed every few hours.
* MoEngage cannot modify the body or key names while streaming the data.

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What is the throughput, average volume, and batch size?">
    The throughput and average volume of each API request depends on the volume of selected events captured into MoEngage. The default batch size (number of events for each API request) is 100.
  </Accordion>

  <Accordion title="What is the retry mechanism of Streams?">
    In case a batch of events fail (any non-2XX response), the entire batch is retried. In total, three retry attempts are made with intervals of 30, 60, and 120 seconds.
  </Accordion>

  <Accordion title="If I pause Streams, can I still get the data later?">
    No. If you pause Streams, data is not collected for exports and cannot be replayed at a later date.
  </Accordion>

  <Accordion title="Does Streams guarantee the latest user attributes?">
    No. Streams is built for near real-time event export. Since user attributes are updated asynchronously, MoEngage cannot guarantee the latest values in the export.
  </Accordion>

  <Accordion title="Can I export historical data using Streams?">
    No. You can only export data generated after the Streams configuration is enabled.
  </Accordion>
</AccordionGroup>
