# API Quickstart

## Step 1 : Configure authentication

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

## 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](/resources/data-cubes/reference.md#metric) to retrieve.                                                                                |
| dimension\_filter\_clauses                     | object | Filters to apply on dimensions before calculating the metric. For more information, see [FilterClause](/resources/data-cubes/reference.md#filterclause). |
| dimensions<mark style="color:red;">\*</mark>   | array  | [Dimensions](/resources/data-cubes/reference.md#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](/resources/data-cubes/reference.md#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](/resources/data-cubes/creating-a-report.md#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](/resources/api-overview.md#single-resource-wrapper) containing a [ReportView](/resources/data-cubes/reference.md#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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.mediarithmics.io/querying-your-data/activities-analytics-queries/api-quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
