# Calendars

You can create any number of [Calendars](https://docs.api.intratool.de/api-reference/calendar/calendars) to categorize [Events](https://docs.api.intratool.de/api-reference/calendar/calendar-events). Each [Calendar](https://docs.api.intratool.de/api-reference/calendar/calendars) can be assigned a different color to differentiate the [Events](https://docs.api.intratool.de/api-reference/calendar/calendar-events) in different [Calendars](https://docs.api.intratool.de/api-reference/calendar/calendars).

## Model Definition

### Relations

| Key      | Relation                                                                               | Type     | Relation Field(s)           |
| -------- | -------------------------------------------------------------------------------------- | -------- | --------------------------- |
| `events` | [CalendarEvents](https://docs.api.intratool.de/api-reference/calendar/calendar-events) | Has many | `calendarEvent.calendar_id` |

### Traits

* `Sortable`

{% hint style="warning" %}
All kinds of [Query Manipulation](https://docs.api.intratool.de/introduction/query-manipulation) are not vailable for `Calendars`.
{% endhint %}

## List

Get a list of all `Calendars`.

**Definition**

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

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response Body**

```json
[
  {
    "id": 1,
    "name": "Allgemein",
    "color": "#2196f3",
    "sort_number": 1,
    "created_at": "2024-06-01 12:00:00",
    "updated_at": "2024-06-01 12:00:00"
  },
  {
    "id": 2,
    "name": "Urlaubskalender",
    "color": "#8bc34a",
    "sort_number": 2,
    "created_at": "2024-06-01 13:00:00",
    "updated_at": "2024-06-01 13:00:00"
  }
]
```

## Show

Show a single `Calendar` by `id`.

**Definition**

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

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 1,
  "name": "Allgemein",
  "color": "#2196f3",
  "sort_number": 1,
  "created_at": "2024-06-01 12:00:00",
  "updated_at": "2024-06-01 12:00:00"
}
```

## Create

Create a new `Calendar`.

**Definition**

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

**Request Keys**

| Key           | Type    | Default            | Description                      |
| ------------- | ------- | ------------------ | -------------------------------- |
| `name`\*      | string  | -                  | The name of the `Calendar`.      |
| `color`\*     | string  | -                  | The HEX color of the `Calendar`. |
| `sort_number` | integer | Current highest +1 | The index of the `Calendar`.     |

Keys with `*` are required.

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/calendars', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'name' => 'Geburtstage',
        'color' => '#810d0b',
        'sort_number' => 3,
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response Body**

```json
{
  "status": "success",
  "data": {
    "id": 3,
    "name": "Geburtstage",
    "color": "#810d0b",
    "sort_number": 3,
    "created_at": "2024-06-01 14:00:00",
    "updated_at": "2024-06-01 14:00:00"
  }
}
```

## Update

Update an existing `Calendar` by `id`.

**Definition**

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

**Request Keys**

| Key           | Type    | Default            | Description                      |
| ------------- | ------- | ------------------ | -------------------------------- |
| `name`        | string  | -                  | The name of the `Calendar`.      |
| `color`       | string  | -                  | The HEX color of the `Calendar`. |
| `sort_number` | integer | Current highest +1 | The index of the `Calendar`.     |

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 3,
    "name": "Geburtstage",
    "color": "#fcb12b",
    "sort_number": 3,
    "created_at": "2024-06-01 14:00:00",
    "updated_at": "2024-06-01 15:00:00"
  }
}
```

## Delete

Delete an existing `Calendar` by `id`.

**Definition**

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

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": []
}
```
