# Departments

## Introduction

`Departments` represent locations or user groups within the customer system and serve as the starting point of the permission system.

They are used to structure organizational units, which are essential for assigning permissions and managing access to content in various modules.

The assignment of content is typically based either on specific [Users](/api-reference/users.md) or on the associated `Department`.

## Model Definition

### Alias

`department`

### Relations

| Key     | Relation                         | Type       | Relation Field(s)     |
| ------- | -------------------------------- | ---------- | --------------------- |
| `user`  | [User](/api-reference/users.md)  | Belongs to | `user_id`             |
| `roles` | [Roles](/api-reference/roles.md) | Has many   | `roles.department_id` |

## List

Get a list of all `Departments`.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/departments`

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 2,
    "name": "Standort 01",
    "user_id": 2,
    "folder_id": null,
    "created_at": "2019-01-15 12:00:00",
    "updated_at": "2019-01-15 12:00:00",
    "deleted_at": null
  },
  {
    "id": 3,
    "name": "Standort 02",
    "user_id": 2,
    "folder_id": null,
    "created_at": "2019-01-15 13:00:00",
    "updated_at": "2019-01-15 13:00:00",
    "deleted_at": null
  }
]
```

## Show

Show a single `Department` by `id`.

**Definition**

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

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 2,
  "name": "Standort 01",
  "user_id": 2,
  "folder_id": null,
  "created_at": "2019-01-15 12:00:00",
  "updated_at": "2019-01-15 12:00:00",
  "deleted_at": null
}
```

## Show availability information

Show the "availability information" for `Departments`

**Definition**

<mark style="color:green;">`GET`</mark> `/api/departments/availability-information`

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "total_available": 10,
  "available": 8,
  "used": 2
}
```

## Create

Create a new `Department`.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/departments`

**Request Keys**

| Key         | Type    | Default | Description                                                                    |
| ----------- | ------- | ------- | ------------------------------------------------------------------------------ |
| `name` \*   | string  | -       | The name of the `Department`.                                                  |
| `folder_id` | integer | -       | The ID of [Folder](/api-reference/folders.md) the `Department` is assigned to. |

Keys with `*` are required.

{% hint style="warning" %}
The request can fail if the maximum number of `Departments` is already reached.
{% endhint %}

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 4,
    "name": "Standort 03",
    "user_id": 2,
    "folder_id": null,
    "created_at": "2019-01-15 14:00:00",
    "updated_at": "2019-01-15 14:00:00",
    "deleted_at": null
  }
}
```

## Update

Update an existing `Department` by `id`.

**Definition**

<mark style="color:blue;">`PUT`</mark> `/api/departments/{id}`

**Request Keys**

| Key         | Type    | Description                                                                    |
| ----------- | ------- | ------------------------------------------------------------------------------ |
| `name`      | string  | The name of the `Department`.                                                  |
| `folder_id` | integer | The ID of [Folder](/api-reference/folders.md) the `Department` is assigned to. |

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/departments/4', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'name' => 'Standort - 03',
    ]
]);

```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 4,
    "name": "Standort - 03",
    "user_id": 2,
    "folder_id": null,
    "created_at": "2019-01-15 14:00:00",
    "updated_at": "2019-01-15 14:30:00",
    "deleted_at": null
  }
}
```

## Delete

Delete an existing `Department` by `id`.

**Definition**

<mark style="color:red;">`DELETE`</mark> `/api/departments/{id}`

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": null
}
```


---

# 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/departments.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.
