# Collection volumes

This page shows you how to get started using the collection volumes mediarithmics API to query the number of elements indexed in mediarithmics.

For each datamart collection, you can get the number of elements which were indexed at a given time.

This API is a mediarithmics [Data cube](https://developer.mediarithmics.io/resources/data-cubes) and works similarly as [Activities analytics queries API](https://developer.mediarithmics.io/querying-your-data/activities-analytics-queries).&#x20;

## Quickstart

<mark style="color:green;">`POST`</mark> `https://api.mediarithmics.com/v1/platform_monitoring/collections`

#### Request Body

| Name                                                         | Type                            | Description                                                                                                                                                                             |
| ------------------------------------------------------------ | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| metrics<mark style="color:red;">\*</mark>                    | array                           | Array of [Metric](https://developer.mediarithmics.io/resources/data-cubes/reference#metric) to retrieve.                                                                                |
| dimension\_filter\_clauses<mark style="color:red;">\*</mark> | object                          | Filters to apply on dimensions before calculating the metric. For more information, see [FilterClause](https://developer.mediarithmics.io/resources/data-cubes/reference#filterclause). |
| dimensions<mark style="color:red;">\*</mark>                 | Dimensions to group metrics by. | [Dimensions](https://developer.mediarithmics.io/resources/data-cubes/reference#dimension) to group metrics by.                                                                          |
| date\_ranges<mark style="color:red;">\*</mark>               | array                           | Periods to analyze. Each date range is an object with a `start_date` and an `end_date`. See [DateRange](https://developer.mediarithmics.io/resources/data-cubes/reference#daterange).   |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": "ok",
    "data": {
        "report_view": {
            "items_per_page": 100,
            "total_items": 7,
            "columns_headers": [
                "date_time",
                "datamart_id",
                "collection",
                "count"
            ],
            "rows": [
                [
                    1637931755000,
                    9999,
                    "USER_POINT",
                    100
                ],
                [
                    1637931755100,
                    9999,
                    "USER_EVENT",
                    50
                ]
            ]
        }
    }
}
```

{% endtab %}
{% endtabs %}

Here is a sample [report request](https://developer.mediarithmics.io/resources/data-cubes/creating-a-report#report-request) body payload with all the important properties:

```
{
    // Retrieve the data in the specified date range
    // Mandatory
    // Tip : you can use relative date formats such as "now-7d/d"
    "date_ranges": [
        {
            "start_date": "2021-10-10T00:00:00",
            "end_date": "2021-10-25T23:59:59"
        }
    ],
    // List of dimensions to retrieve
    "dimensions": [
        {
            "name": "date_time"
        },
        {
            "name": "community_id"
        },
        {
            "name": "collection"
        }
    ],
    // Filters on dimensions
    "dimension_filter_clauses": {
        "operator": "AND",
        "filters": [
            {
                "dimension_name": "community_id",
                "operator": "EXACT",
                "expressions": [
                    100
                ]
            }
        ]
    },
    // List of metrics to retrieve
    "metrics": [
        {
            "expression": "count"
        }
    ]
}
```

## Measure <a href="#undefined" id="undefined"></a>

Collection counts are retrieved every day through OTQL queries, for each indexed collection. A collection is indexed if it is in your schema. Volumes for non indexed collections are not computed. For more information on collections indexing, see [Data model](https://developer.mediarithmics.io/schema).

Hereunder is a description of the queries we use to compute the volumes.

{% hint style="info" %}
The OTQL query is automatically adapted in case the runtime schema is using the [@Mirror directive](https://developer.mediarithmics.io/schema#mirror).
{% endhint %}

| Collection name | OTQL query                         |
| --------------- | ---------------------------------- |
| `UserPoint`     | SELECT @count{} FROM UserPoint     |
| `UserAccount`   | SELECT @count{} FROM UserAccount   |
| `UserEmail`     | SELECT @count {} FROM UserEmail    |
| `UserAgent`     | SELECT @count {} FROM UserAgent    |
| `UserProfile`   | SELECT @count {} FROM UserProfile  |
| `UserActivity`  | SELECT @count {} FROM UserActivity |
| `UserEvent`     | SELECT @count {} FROM UserEvent    |
| `UserSegment`   | SELECT @count {} FROM UserSegment  |
| `UserChoice`    | SELECT @count {} FROM UserChoice   |
| `UserScenario`  | SELECT @count {} FROM UserScenario |

## Retention

These aggregated stats are kept for two years.

## Supported dimensions and metrics

See [Dimensions and metrics](https://developer.mediarithmics.io/advanced-usages/platform-monitoring/collection-volumes/dimensions-and-metrics) for the complete list of supported dimensions and metrics.

## Learning more about data cubes

This endpoint is a mediarithmics [Data cube](https://developer.mediarithmics.io/resources/data-cubes). You can find documentation on how data cubes work and which are available in the specific documentation section.
