# API Quickstart

## Step 1 : Configure authentication

This quickstart guide uses the [Long term access tokens](https://developer.mediarithmics.io/resources/api-overview/authentication#long-term-access-tokens) authentication method. Choose and configure your own authentication method. For more information, see [Authentication](https://developer.mediarithmics.io/resources/your-first-integration/make-the-first-bulk-import/api-basics/authentication).

## Step 2 : API call

<mark style="color:green;">`POST`</mark> `https://api.mediarithmics.com/v1/datamarts/:datamartId/user_activities_analytics`

#### Query Parameters

| Name                                         | Type   | Description                     |
| -------------------------------------------- | ------ | ------------------------------- |
| datamartId<mark style="color:red;">\*</mark> | number | The ID of the datamart to query |

#### 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                     | 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>   | array  | [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 " %}

```javascript
{
    "status": "ok",
    "data": {
        "report_view": {
            "items_per_page": 100,
            "total_items": 7,
            "columns_headers": [
                "type"
            ],
            "rows": [
                [
                    "DISPLAY_AD"
                ],
                [
                    "EMAIL"
                ],
                [
                    "SITE_VISIT"
                ],
                [
                    "USER_SCENARIO_NODE_ENTER"
                ],
                [
                    "USER_SCENARIO_NODE_EXIT"
                ],
                [
                    "USER_SCENARIO_START"
                ],
                [
                    "USER_SCENARIO_STOP"
                ]
            ]
        }
    }
}
```

{% endtab %}
{% endtabs %}

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

```json
{
    // Retrieve the data in the specified date range
    // Mandatory. The data is only queryable for the last 4 months
    // Only one range is allowed now, but the API is prepared to accept
    // multiple ranges in the future.
    // Tip : you can use dates in "now-Xd/d" format as in OTQL queries
    "date_ranges": [
        {
            "start_date": "2021-10-10T00:00:00",
            "end_date": "2021-10-25T23:59:59"
        }
    ],
    // List of dimensions to retrieve
    "dimensions": [
        {
            "name": "date_yyyy_mm_dd"
        },
        {
            "name": "channel_id"
        }
    ],
    // Filters on dimensions
    "dimension_filter_clauses": {
        "operator": "OR",
        "filters": [
            {
                "dimension_name": "type",
                "operator": "EXACT",
                "expressions": [
                    "SITE_VISIT"
                ]
            }
        ]
    },
    // Order by dates, beginning with the most recent
    "order_by": {
            "field_name": "-date_yyyy_mm_dd"
    },
    // List of metrics to retrieve
    "metrics": [
        {
            "expression": "users"
        },
          {
            "expression": "number_of_transactions"
        }
    ]
}
```

The API will answer with a [Single resource wrapper](https://developer.mediarithmics.io/resources/api-overview#single-resource-wrapper) containing a [ReportView](https://developer.mediarithmics.io/resources/data-cubes/reference#reportview).

```json
{
    "status": "ok",
    "data": {
        "report_view": {
            // Note : pagination not implemented yet
            "items_per_page": 100,
            "total_items": 100,
            // To know which data is in which column
            "columns_headers": [
                "date_yyyy_mm_dd",
                "channel_id",
                "users",
                "number_of_transactions"
            ],
            // Data
            "rows": [
                [
                    "2021-10-10",
                    666,
                    3881,
                    17800.0
                ],
                [
                    "2021-10-10",
                    555,
                    1838,
                    4200.0
                ],
                [
                    "2021-10-11",
                    666,
                    532,
                    3900.0
                ],
                [
                    "2021-10-11",
                    555,
                    8,
                    100.0
                ]
                // ...[
            ]
        }
    }
}
```

Congratulations! You've sent your first request to the Activities analytics API.
