# UserActivity API

The **user activities** endpoint gives you the ability to retrieve & delete any activities (and attached events) on a given UserPoint.

## Retrieve activities & events from a UserPoint

<mark style="color:blue;">`GET`</mark> `https://api.mediarithmics.com/v1/datamarts/:datamartId/user_timelines/:userpointId/user_activities?filters=:filters`

#### Path Parameters

| Name                                          | Type   | Description                                                 |
| --------------------------------------------- | ------ | ----------------------------------------------------------- |
| datamartId<mark style="color:red;">\*</mark>  | String | The ID of the datamart want to retrieve activities for      |
| userpointId<mark style="color:red;">\*</mark> | String | The ID of the UserPoint you want to retrieve activities for |

#### Query Parameters

| Name    | Type   | Description                                    |
| ------- | ------ | ---------------------------------------------- |
| filters | String | Filter(s) to select appropriat user activities |

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

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Delete activities & events from a UserPoint

<mark style="color:red;">`DELETE`</mark> `https://api.mediarithmics.com/v1/datamarts/:datamartId/user_timelines/:userpointId/user_activities?filters=:filters`

#### Path Parameters

| Name                                          | Type   | Description                                                 |
| --------------------------------------------- | ------ | ----------------------------------------------------------- |
| datamartId<mark style="color:red;">\*</mark>  | String | The ID of the datamart want to retrieve activities for      |
| userpointId<mark style="color:red;">\*</mark> | String | The ID of the UserPoint you want to retrieve activities for |

#### Query Parameters

| Name    | Type   | Description                                    |
| ------- | ------ | ---------------------------------------------- |
| filters | String | Filter(s) to select appropriat user activities |

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

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Filters

As mentionned above, filters are optional and give you the ability to narrow your query. You can apply filters on any custom fields you have in your activity object as well as the following proprietary fields:

* $unique\_key
* $type
* $channel\_id
* $ts (through start\_ts & end\_ts keywords)

To apply any filter, mention the field on which you want your filter to be applied, followed by double equal (**==**), then by value(s) for the field to be matched against.

Note that:

* You can provide in your query multiple filters by seperating filters with a comma (**,**). In that case, it will be considered as an "AND" between those filters
* A filter can take multiple values by separating values with a pipe (**|**). In that case, it will be considered as an "OR" between those values

## Query examples

```
# As explained above, user activities query is always for a particular datamart (1649) & userpoint (dff34408-6cc1-4531-86c5-bac8da9ebac9)
# Retrieve all activities 
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities"

# Retrieve all activities for a given channel (4307)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=$channel_id==4307"

# Retrieve all activities for a given activity type (SITE_VISIT)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=$type==SITE_VISIT"

# Retrieve all activities for several activity types (SITE_VISIT & APP_VISIT)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=$type==SITE_VISIT|APP_VISIT"

# Retrieve a given activity (17928440-e72f-11ec-aad0-d12e54ffd215)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=$unique_key==17928440-e72f-11ec-aad0-d12e54ffd215"

# Retrieve all activities ingested after a particular date (14/06/2022 10:38:47)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=start_ts==1655195927000"

# Retrieve all activities ingested before a particular date (13/07/2022 13:15:00)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=end_ts==1657717207000"

# Retrieve all activities ingested between 2 dates (between 14/06/2022 10:38:47 & 13/07/2022 13:15:00)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=start_ts==1655195927000,end_ts==1657717207000"

# Retrieve all activities ingested between 2 dates for a given channel (between 14/06/2022 10:38:47 & 13/07/2022 13:15:00 for channel 4307)
curl -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=start_ts==1655195927000,end_ts==1657717207000,$channel_id==4307"

# Delete a given activity (17928440-e72f-11ec-aad0-d12e54ffd215)
curl -X DELETE -k -H "Authorization: <MICS_API_KEY>" -H "content-Type: application/json" "https://api.mediarithmics.com/v1/datamarts/1649/user_timelines/dff34408-6cc1-4531-86c5-bac8da9ebac9/user_activities?filters=$unique_key==17928440-e72f-11ec-aad0-d12e54ffd215"

```


---

# 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/useractivity-api.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.
