# UserActivities

## Introduction

`UserActivities` track certain activities that the related [User](/api-reference/users.md) initiates and record the [Department](/api-reference/departments.md) in which the activity took place.

Each `UserActivity` has a concrete [type](#types) which defines the kind of activity that is tracked.

An activity is uniquely identified by the combination of the `type` and the related [User](/api-reference/users.md). The associated [Department](/api-reference/departments.md) reflects the user's most recently active location.

The fields `created_at` and `updated_at` indicate the time of the first and most recent occurrence of the activity, respectively.

Activities are only recorded through the use of the intratool application itself and not via the API.

## Model Definition

### Alias

`userActivity`

### Relations

| Key          | Relation                                    | Type       | Relation Field(s) |
| ------------ | ------------------------------------------- | ---------- | ----------------- |
| `user`       | [User](/api-reference/users.md)             | Belongs to | `user_id`         |
| `department` | [Department](/api-reference/departments.md) | Belongs to | `department_id`   |

### Types

* `login` - A login activity of the related [User](/api-reference/users.md).
* `logout` - A logout activity of the related [User](/api-reference/users.md).
* `general` - Any activity of the related [User](/api-reference/users.md).

## List

Get a list of all `UserActivities`.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/user-activities`

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/user-activities', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 1,
    "user_id": 3,
    "department_id": 2,
    "type": "login",
    "created_at": "2025-05-15 12:00:00",
    "updated_at": "2025-05-15 12:00:00"
  },
  {
    "id": 2,
    "user_id": 3,
    "department_id": 2,
    "type": "general",
    "created_at": "2025-05-15 12:00:00",
    "updated_at": "2025-05-15 15:00:00"
  },
  {
    "id": 3,
    "user_id": 3,
    "department_id": 2,
    "type": "logout",
    "created_at": "2025-05-15 15:00:00",
    "updated_at": "2025-05-15 15:00:00"
  }
]
```

## Show

Show a single `UserActivity` by `id`.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/user-activities/{id}`

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/user-activities/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 1,
  "user_id": 3,
  "department_id": 2,
  "type": "login",
  "created_at": "2025-05-15 12:00:00",
  "updated_at": "2025-05-15 12:00:00"
}
```


---

# 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://docs.api.intratool.de/api-reference/user-activities.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.
