# CalendarEvents

The calendar allows `CalendarEvents` to be categorized by [Calendars](/api-reference/calendar/calendars.md) and then assigned to relevant [Departments](/api-reference/departments.md).

## Model Definition

### Alias

`calendarEvent`

### Relations

| Key           | Relation                                         | Type            | Relation Field(s)  |
| ------------- | ------------------------------------------------ | --------------- | ------------------ |
| `user`        | [User](/api-reference/users.md)                  | Belongs to      | `user_id`          |
| `calendar`    | [Calendar](/api-reference/calendar/calendars.md) | Belongs to      | `calendar_id`      |
| `departments` | [Departments](/api-reference/departments.md)     | Belongs to many | Intermediate table |

### Computed Properties

* `hash` - The hashed `id` of the `CalendarEvent`.

### Traits

* `TriggersNotifications`

### Interval Syntax

| Interval   | Sub-Type      | Syntax              | Description                                                            |
| ---------- | ------------- | ------------------- | ---------------------------------------------------------------------- |
| daily      |               | `d:::1`             | Repeats every day.                                                     |
| weekly     |               | `w:::1`             | Repeats every week.                                                    |
|            | with weekdays | `w:::1d::1,2,3,4,5` | Repeats on the 1st, 2nd, 3rd, 4th and 5th day each week.               |
| monthly    |               |                     |                                                                        |
|            | day           | `m:::1d::1`         | Repeats on the 1st day each month.                                     |
|            | week          | `m:::1w::1d::1`     | Repeats on the 1st day each week each month.                           |
| yearly     |               |                     |                                                                        |
|            | day           | `y:::1d::1`         | Repeats on the 1st day each year.                                      |
|            | week          | `y:::1w::1d::1`     | Repeats on the 1st day each week each month.                           |
| recurrence |               | `r:::1`             | Ends the repeating after 1 recurrence. Only usable for `interval_end`. |

{% hint style="warning" %}
All kinds of [Query Manipulation](/introduction/query-manipulation.md) are not vailable for `CalendarEvents`.
{% endhint %}

## List

Get a list of all `CalendarEvents` the current authenticated [User](/api-reference/users.md) is allowed to view.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/calendar-events`

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response Body**

```json
[
  {
    "id": 1,
    "user_id": 8,
    "calendar_id": 1,
    "title": "CalendarEvent-1",
    "all_day": 1,
    "start": "2020-03-17 00:00:00",
    "end": "2020-03-23 00:00:00",
    "interval": {
      "type": "weekly",
      "each_weeks": 1,
      "days_in_week": [3]
    },
    "interval_end": null,
    "location": null,
    "description": null,
    "created_at": "2020-03-05 09:54:26",
    "updated_at": "2020-03-05 09:54:26",
    "repeat_date": false,
    "hash": "0gzevr2xpolgmwlm4nyd86wj",
    "color": "#009688",
    "user": {
      "id": 8,
      "role_id": 3,
      "username": "jeremy.doe",
      "first_name": "Jeremy",
      "last_name": "Doe",
      "active": 1,
      "group_account": 0,
      "deleted_at": null,
      "blacked_out_at": null,
      "full_name": "Jeremy Doe",
      "role": {
        "id": 3,
        "department_id": 3,
        "name": "Usergroup-2",
        "department": {
          "id": 3,
          "name": "Usergroup-2"
        }
      }
    },
    "calendar": {
      "id": 1,
      "name": "Calendar-1",
      "color": "#009688"
    },
    "departments": [
      {
        "id": 2,
        "name": "Usergroup-1"
      },
      {
        "id": 3,
        "name": "User-Group-2"
      },
      {
        "id": 4,
        "name": "User-Group-3"
      }
    ]
  },
  {
    "id": 2,
    "user_id": 8,
    "calendar_id": 2,
    "title": "CalendarEvent-2",
    "all_day": 1,
    "start": "2020-03-03 00:00:00",
    "end": "2020-03-09 00:00:00",
    "interval": null,
    "interval_end": null,
    "location": null,
    "description": null,
    "created_at": "2020-03-05 09:53:38",
    "updated_at": "2020-03-05 09:53:38",
    "repeat_date": false,
    "hash": "0p8mweyzxnlzevlrd5vgk47j",
    "color": "#CDDC39",
    "user": {
      "id": 8,
      "role_id": 3,
      "username": "jeremy.doe",
      "first_name": "Jeremy",
      "last_name": "Schmidt",
      "active": 1,
      "group_account": 0,
      "deleted_at": null,
      "blacked_out_at": null,
      "full_name": "Jeremy Doe",
      "role": {
        "id": 3,
        "department_id": 3,
        "name": "UserGroup-2",
        "department": {
          "id": 3,
          "name": "UserGroup-2"
        }
      }
    },
    "calendar": {
      "id": 2,
      "name": "Calendar-2",
      "color": "#CDDC39"
    },
    "departments": [
      {
        "id": 2,
        "name": "Usergroup-1"
      },
      {
        "id": 3,
        "name": "Usergroup-2"
      }
    ]
  }
]
```

## Show

Show a single `CalendarEvent` by `id`.

**Definition**

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

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 1,
  "user_id": 8,
  "calendar_id": 1,
  "title": "CalendarEvent-1",
  "all_day": 1,
  "start": "2020-03-17 00:00:00",
  "end": "2020-03-23 00:00:00",
  "interval": {
    "type": "weekly",
    "each_weeks": 1,
    "days_in_week": [3]
  },
  "interval_end": null,
  "location": null,
  "description": null,
  "created_at": "2020-03-05 09:54:26",
  "updated_at": "2020-03-05 09:54:26",
  "repeat_date": false,
  "hash": "0gzevr2xpolgmwlm4nyd86wj",
  "color": "#009688",
  "user": {
    "id": 8,
    "role_id": 3,
    "username": "jeremy.doe",
    "first_name": "Jeremy",
    "last_name": "Doe",
    "active": 1,
    "group_account": 0,
    "deleted_at": null,
    "blacked_out_at": null,
    "full_name": "Jeremy Doe",
    "role": {
      "id": 3,
      "department_id": 3,
      "name": "Usergroup-2",
      "department": {
        "id": 3,
        "name": "Usergroup-2"
      }
    }
  },
  "calendar": {
    "id": 1,
    "name": "Calendar-1",
    "color": "#009688"
  },
  "departments": [
    {
      "id": 2,
      "name": "Usergroup-1"
    },
    {
      "id": 3,
      "name": "User-Group-2"
    },
    {
      "id": 4,
      "name": "User-Group-3"
    }
  ]
}
```

## Create

Create a new `CalendarEvent`.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/calendar-events`

**Request Keys**

| Key                | Type       | Default | Description                                                                                                         |
| ------------------ | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
| `calendar_id`\*    | integer    | -       | The related [Calendar](/api-reference/calendar/calendars.md).                                                       |
| `department_ids`\* | string     | -       | The [Departments](/api-reference/departments.md) that are allowed to see the `CalendarEvent` (separated by commas). |
| `title`\*          | string     | -       | The title of the `CalendarEvent`.                                                                                   |
| `all_day`\*        | boolean    | -       | Whether the `CalendarEvent` is a full day appointment.                                                              |
| `start`\*          | date\_time | -       | When the `CalendarEvent` starts.                                                                                    |
| `end`\*            | date\_time | -       | When the `CalendarEvent` ends.                                                                                      |
| `interval`         | string     | -       | When to repeat the `CalendarEvent`.                                                                                 |
| `interval_end`     | string     | -       | When to end the repeating.                                                                                          |
| `location`         | string     | -       | Location of the `CalendarEvent`.                                                                                    |
| `description`      | string     | -       | Description of the `CalendarEvent`.                                                                                 |

Keys with `*` are required.

**Advanced Key-Specifications**

* `interval` - The syntax for intervals can be found [here](#interval-syntax).
* `interval_end` - The syntax for intervals can be found [here](#interval-syntax).

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/calendar-events', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'user_id' => 3,
        'calendar_id' => 1,
        'department_ids' => '2,3',
        'title' => 'CalendarEvent-1',
        'all_day' => true,
        'start' => '2020-01-06 00:00:00',
        'end' => '2020-02-06 00:00:00',
        'interval' => 'w:::1',
        'interval_end' => 'r:::10',
        'location' => '',
        'description' => ''
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response Body**

```json
{
  "status": "success",
  "data": {
    "user_id": "8",
    "calendar_id": "1",
    "title": "CalendarEvent-1",
    "all_day": "1",
    "start": "2020-01-06 00:00:00",
    "end": "2020-02-06 00:00:00",
    "interval": {
      "type": "weekly",
      "each_weeks": 1
    },
    "interval_end": {
      "type": "repeats",
      "repeats": 3
    },
    "updated_at": "2020-06-05 17:31:06",
    "created_at": "2020-06-05 17:31:06",
    "id": 1,
    "hash": "6o8m0kz5yw10xx1pr9e4vxj2",
    "color": "#2196F3",
    "departments": [
      {
        "id": 2,
        "name": "UserGroup-1",
        "created_at": "2018-09-11 12:47:02",
        "updated_at": "2018-09-11 12:47:02",
        "deleted_at": null
      },
      {
        "id": 3,
        "name": "UserGroup-2",
        "created_at": "2018-09-11 12:47:08",
        "updated_at": "2018-09-11 12:47:08",
        "deleted_at": null
      }
    ],
    "user": {
      "id": 8,
      "username": "jeremy.doe",
      "first_name": "Jeremy",
      "last_name": "Doe",
      "active": 1,
      "group_account": 1,
      "role_id": 2,
      "profile_picture": null,
      "street": null,
      "zipcode": null,
      "city": null,
      "email": null,
      "phone": null,
      "birthdate": null,
      "gender": null,
      "entering_date": null,
      "leaving_date": null,
      "staff_number": null,
      "wants_email_notifications": 0,
      "created_at": "2018-09-11 13:47:07",
      "updated_at": "2019-04-26 16:04:02",
      "deactivated_at": null,
      "deleted_at": null,
      "blacked_out_at": null,
      "default_route": "",
      "full_name": " "
    },
    "calendar": {
      "id": 1,
      "name": "Calendar-1",
      "color": "#2196F3",
      "sort_number": 1,
      "created_at": "2018-09-11 00:00:00",
      "updated_at": "2018-09-13 19:15:15"
    }
  }
}
```

## Update

Update an existing `CalendarEvent` by `id`.

**Definition**

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

**Request Keys**

| Key              | Type       | Default | Description                                                                                                         |
| ---------------- | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
| `calendar_id`    | integer    | -       | The related [Calendar](/api-reference/calendar/calendars.md)                                                        |
| `department_ids` | string     | -       | The [Departments](/api-reference/departments.md) that are allowed to see the `CalendarEvent` (separated by commas). |
| `title`          | string     | -       | The title of the `CalendarEvent`.                                                                                   |
| `all_day`        | boolean    | -       | Whether the `CalendarEvent` is a full day appointment.                                                              |
| `start`          | date\_time | -       | When the `CalendarEvent` starts.                                                                                    |
| `end`            | date\_time | -       | When the `CalendarEvent` ends.                                                                                      |
| `interval`       | string     | -       | When to repeat the `CalendarEvent`.                                                                                 |
| `interval_end`   | string     | -       | When to end the repeating.                                                                                          |
| `location`       | string     | -       | Location of the `CalendarEvent`.                                                                                    |
| `description`    | string     | -       | Description of the `CalendarEvent`.                                                                                 |

**Advanced Key-Specifications**

* `interval` - The syntax for intervals can be found [here](#interval-syntax).
* `interval_end` - The syntax for intervals can be found [here](#interval-syntax).

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/calendar-events/3', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
        'interval_end' => 'r:::5'
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "user_id": 8,
    "calendar_id": 1,
    "title": "CalendarEvent-1",
    "all_day": 1,
    "start": "2020-01-06 00:00:00",
    "end": "2020-02-06 00:00:00",
    "interval": {
      "type": "weekly",
      "each_weeks": 1
    },
    "interval_end": {
      "type": "repeats",
      "repeats": 5
    },
    "location": null,
    "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
    "created_at": "2020-06-05 17:31:06",
    "updated_at": "2020-06-05 17:31:06",
    "hash": "6o8m0kz5yw10xx1pr9e4vxj2",
    "color": "#2196F3",
    "calendar": {
      "id": 1,
      "name": "Calendar-1",
      "color": "#2196F3",
      "sort_number": 1,
      "created_at": "2018-09-11 00:00:00",
      "updated_at": "2018-09-13 19:15:15"
    }
  }
}
```

## Delete

Delete an existing `CalendarEvent` by `id`.

**Definition**

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

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

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


---

# 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/calendar/calendar-events.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.
