# Aggregated Events

From the product's cloud instance, we get aggregated usage data that provides consolidated metrics for better insights into product usage patterns. This API enables ingestion of aggregated product data with two distinct modes:

**Domain Mode**: Aggregate usage data at the company level.

**User Mode**: Aggregate usage data at the individual user level.&#x20;

{% hint style="info" %}
**Important Note:** The Product API integration is fully dependent on the configuration of custom metrics in the **Product Usage Settings**.\
Without these metrics, data sent via the API will not be received or processed in the Reo.Dev platform. Please refer to [How to Configure Product Usage Metrics in Settings](https://docs.reo.dev/configurations/product-usage) to ensure your metrics are correctly set up before implementing the Product API.
{% endhint %}

### API Structure

| Header       | Description                                             | Data type |
| ------------ | ------------------------------------------------------- | --------- |
| X-API-KEY    | Generated Reo.Dev `<API_KEY>` for authorization.        | string    |
| Content-Type | Request content-type is always set to application/json. | string    |

**Endpoint**: [`https://ingest.reo.dev/api/product/aggregateusage`](https://ingest.reo.dev/api/product/aggregateusage)

**Method**: `POST`

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

### Domain Mode Example

```
curl --location 'https://ingest.reo.dev/api/product/aggregateusage' \
--header 'X-API-KEY: <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
  "payload": {
    "mode": "DOMAIN",
    "activity_type": "DEMO_LOGIN",
    "source": "PRODUCT_CLOUD",
    "environment": "PRODUCTION",
    "event_id": 1231231232,
    "event_at": 639303296,
    "user_id": "",
    "user_id_type": "",
    "count": 1250,
    "domain": "reo.dev",
    "ip_addr": "",
    "product_id": "reoWebApp",
    "user_agent": "Mozilla/5.0 (Macintosh, Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    "meta": {
      "property1": "value1",
      "property2": "value2"
    }
  }
}'

```

### User Mode Example

```
curl --location 'https://ingest.reo.dev/api/product/aggregateusage' \
--header 'X-API-KEY: <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
  "payload": {
    "mode": "USER",
    "activity_type": "probe",
    "source": "PRODUCT_CLOUD",
    "environment": "PRODUCTION",
    "event_id": 1231231232,
    "event_at": 639303296,
    "user_id": "brian@reo.dev",
    "user_id_type": "EMAIL",
    "count": 40,
    "domain": "",
    "ip_addr": "",
    "product_id": "reoWebApp",
    "user_agent": "Mozilla/5.0 (Macintosh, Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    "meta": {
      "property1": "value1",
      "property2": "value2"
    }
  }
}'

```

### Tenant API Key

To access your API key, navigate to: **Settings → Integrations → API Keys → Product Usage API**

* Admins can generate and copy the key
* Non-admin users can only view and copy the existing key

### Parameters

| Parameter                                      | Description                                                                                                                                 | Data Type | Possible Values                                     | Example                                                             |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------- | ------------------------------------------------------------------- |
| **mode** (Required)                            | Aggregation mode for the data                                                                                                               | enum      | `DOMAIN`, `USER`                                    | `"DOMAIN"`                                                          |
| **source** (Required)                          | Source of the activity                                                                                                                      | enum      | `PRODUCT_CLOUD`                                     | `"PRODUCT_CLOUD"`                                                   |
| **activity\_type** (Required)                  | Usage Metrics of the product. The definition of primary, secondary1, secondary2, should match with metrics defined in the Reo.Dev settings. | string    | Keys defined in metrics                             | `"LOGIN_ACTIVITY"`                                                  |
| **environment** (optional)                     | Environment where product has been deployed                                                                                                 | string    |                                                     | `"PRODUCTION"`                                                      |
| **user\_id\_type** (mandatory)                 | Type of user ID such as email, Social, LinkedIn, GitHub, Username                                                                           | enum      | `EMAIL`, `SOCIAL`, `LINKEDIN`, `GITHUB`, `USERNAME` | `"EMAIL"`                                                           |
| **user\_id** (mandatory)                       | Unique user ID captured for a customer                                                                                                      | string    |                                                     | `"brian@reo.dev"`                                                   |
| **count** (mandatory)                          | Aggregated count of the activity/usage                                                                                                      | integer   |                                                     | `1250`                                                              |
| <p><strong>ip\_addr</strong><br>(optional)</p> | IP address of the system from where the user has logged in.                                                                                 | string    |                                                     | `"192.127.0.0”`                                                     |
| **domain** (optional)                          | Domain associated with the user or activity                                                                                                 | string    |                                                     | `"reo.dev"`                                                         |
| **event\_id** (optional)                       | A unique identifier for this API call                                                                                                       | string    |                                                     | `1231231232`                                                        |
| **event\_at** (mandatory)                      | The time at which this API request was triggered (Formatted as a UNIX epoch in seconds)                                                     | integer   |                                                     | `639303296`                                                         |
| **product\_id** (Required)                     | Unique identifier of your product                                                                                                           | string    |                                                     | `"reoWebApp"`                                                       |
| **user\_agent** (optional)                     | Additional browser properties                                                                                                               | string    |                                                     | `"Mozilla/5.0 (Macintosh, Intel Mac OS X 10_15_7)...Safari/537.36"` |
| **meta** (optional)                            | Any other parameter that needs to be sent                                                                                                   | object    |                                                     | `{"property1":"value1","property2":"value2"}`                       |

### Sample JSON Request (Domain Mode)

```
{
  "payload": {
    "mode": "DOMAIN",
    "activity_type": "secondary23",
    "source": "PRODUCT_CLOUD",
    "environment": "PRODUCTION",
    "event_id": 1231231232,
    "event_at": 639303296,
    "user_id": "",
    "user_id_type": "",
    "count": 1250,
    "domain": "www.reo.dev",
    "ip_addr": "",
    "product_id": "reoWebApp",
    "user_agent": "Mozilla/5.0 (Macintosh, Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    "meta": {
      "property1": "value1",
      "property2": "value2"
    }
  }
}

```

### Sample JSON Request (User Mode)

<pre><code><strong>{
</strong>  "payload": {
    "mode": "USER",
    "activity_type": "LOGIN_ACTIVITY",
    "source": "PRODUCT_CLOUD",
    "environment": "PRODUCTION",
    "event_id": 1231231232,
    "event_at": 639303296,
    "user_id": "brian@reo.dev",
    "user_id_type": "EMAIL",
    "count": 1250,
    "domain": "",
    "ip_addr": "",
    "product_id": "reoWebApp",
    "user_agent": "Mozilla/5.0 (Macintosh, Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    "meta": {
      "property1": "value1",
      "property2": "value2"
    }
  }
}

</code></pre>

### Sample JSON Response \[Success]

```
{
  "response_code": "200",
  "response": "Aggregated Data Uploaded",
  "status": "success"
}

```

### Sample JSON Response \[Wrong API Key]

```
{
  "response_code": 400,
  "response": "Authentication Failure",
  "status": "failure"
}

```

### Sample JSON Response \[Invalid Mode]

```
{
  "response_code": 400,
  "response": "Invalid mode. Supported modes: DOMAIN, USER",
  "status": "failure"
}
```
