# Aggregated Events

If you have an open source offering with telemetry functionality to collect anonymous usage or event data, you can use the Product Usage API to share aggregated data with Reo.Dev.

**Important**: Either `domain` or `ip_addr` must be provided in the payload - they are conditionally required based on data availability.

From the aggregated telemetry data, we should be able to get:

* IP address of the system OR Domain information (one is required)
* Aggregated usage counts
* Activity Details

From the telemetry data, we will be able to enrich the:

* IP address and find out the company to which the user belongs
* Domain mapping for company association

**Note**: Either `domain` or `ip_addr` must be provided - they are conditionally required based on availability.

With the aggregated data, we will map the product usage at a domain level and ultimately to the company to which the usage is associated.

{% 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    |

```
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": "secondary23",
    "source": "TELEMETRY",
    "environment": "PRODUCTION",
    "event_id": 1231231232,
    "event_at": 639303296,
    "domain": "",
    "ip_addr": "156.59.87.83",
    "count": 1250,
    "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 →Configurations → API Keys → Product Usage API**

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

<figure><img src="https://2705882080-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fx46P5sAHxDG7PqOdVLxI%2Fuploads%2FMNfWFmp2kiAY7M83T5lI%2Fimage.png?alt=media&#x26;token=3cbe5d9e-a87f-45f5-84ec-3ecc3e2ca1f9" alt=""><figcaption></figcaption></figure>

### Parameters

| Parameter                     | Description                                                                                                                                                | Data Type | Possible Values                               | Example                                                                                                                   |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **mode** (Required)           | Aggregation mode for the telemetry data                                                                                                                    | enum      | `DOMAIN`                                      | `"DOMAIN"`                                                                                                                |
| **source** (Required)         | Source of the activity                                                                                                                                     | enum      | `TELEMETRY`                                   | `"TELEMETRY"`                                                                                                             |
| **activity\_type** (Required) | Usage Metrics of the product. The definition of primary, secondary1, secondary2, and secondary23 should match with metrics defined in the Reo.Dev settings | string    | Keys defined in metrics section in Reo.dev UI | `"secondary23"`                                                                                                           |
| **environment** (optional)    | Environment where product has been deployed                                                                                                                | string    |                                               | `"PRODUCTION"`                                                                                                            |
| **count** (mandatory)         | Aggregated count of the telemetry events/usage                                                                                                             | integer   |                                               | `1250`                                                                                                                    |
| **ip\_addr** (conditional)    | IP address of the system from where the telemetry data originated. Required if `domain` is not provided                                                    | string    |                                               | `"156.59.87.83"`                                                                                                          |
| **domain** (conditional)      | Domain associated with the telemetry data. Required if `ip_addr` is not provided                                                                           | string    |                                               | `"reo.dev"`                                                                                                               |
| **event\_id** (optional)      | A unique identifier for the API call                                                                                                                       | string    |                                               | `193ef456430`                                                                                                             |
| **event\_at** (mandatory)     | The time at which the API call was made (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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"` |
| **meta** (optional)           | Any other parameter that needs to be sent                                                                                                                  | object    |                                               | `{"property1":"value1","property2":"value2"}`                                                                             |

### Sample JSON Request

```
{
  "payload": {
    "mode": "DOMAIN",
    "activity_type": "secondary23",
    "source": "TELEMETRY",
    "environment": "PRODUCTION",
    "event_id": 1231231232,
    "event_at": 639303296,
    "count": 1250,
    "ip_addr": "156.59.87.83",
    "domain": "",
    "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 Response \[Success]

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

```

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

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