# Tags

## Introduction

`Tags` are used to categorize and organize various entities within the system. They help in filtering, searching, and managing content efficiently across modules.

`Tags` can be grouped into [TagGroups](tag-groups) and are assignable to different [TaggableSections](taggable-sections).

## Model Definition

### Alias

`tag`

### Relations

| Key                          | Relation                             | Type            | Relation Field(s)                                                                                |
| ---------------------------- | ------------------------------------ | --------------- | ------------------------------------------------------------------------------------------------ |
| `user`                       | [User](../users)                     | Belongs to      | `user_id`                                                                                        |
| `tagGroups`                  | [TagGroup](tag-groups)               | Belongs to many | `tag_tag_group.tag_id`                                                                           |
| `restrictedTaggableSections` | [TaggableSection](taggable-sections) | Morph to many   | `taggable_section_restrictbale.restrictable_type, taggable_section_restrictbale.restrictable_id` |

## List by section

Get a list of all `Tags` by [TaggableSection](taggable-sections).

**Definition**

<mark style="color:green;">`GET`</mark> `/api/tags/allowed/{taggableSection}`

**Example Request**

{% tabs %}
{% tab title="PHP" %}
```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/tags/allowed/infoboard', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```
{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 1,
    "user_id": 2,
    "title": "Tag 1",
    "color": "#061da4",
    "created_at": "2019-06-15 12:00:00",
    "updated_at": "2019-06-15 12:00:00",
    "deleted_at": null
  },
  {
    "id": 2,
    "user_id": 2,
    "title": "Tag 2",
    "color": "#1098b3",
    "created_at": "2019-06-15 13:00:00",
    "updated_at": "2019-06-15 13:00:00",
    "deleted_at": null
  }
]
```

## \[Adm.] List

Get a list of all `Tags`.

**Definition**

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

**Example Request**

{% tabs %}
{% tab title="PHP" %}
```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/tags', [
    'headers' => ['Authorization' => 'Bearer {accessToken}'],
]);
```
{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 1,
    "title": "Important",
    "color": "#ff0000",
    "user_id": 2,
    "created_at": "2019-06-16 12:00:00",
    "updated_at": "2019-06-16 12:00:00",
    "deleted_at": null
  },
  {
    "id": 2,
    "title": "Internal",
    "color": "#00ff00",
    "user_id": 3,
    "created_at": "2019-06-16 13:00:00",
    "updated_at": "2019-06-16 13:00:00",
    "deleted_at": null
  }
]
```

## \[Adm.] Show

Show a single `Tag` by `id`.

**Definition**

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

**Example Request**

{% tabs %}
{% tab title="PHP" %}
```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/tags/1', [
    'headers' => ['Authorization' => 'Bearer {accessToken}'],
]);
```
{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 1,
  "title": "Important",
  "color": "#ff0000",
  "user_id": 2,
  "created_at": "2019-06-16 12:00:00",
  "updated_at": "2019-06-16 12:00:00",
  "deleted_at": null
}
```

## Create

Create a new `Tag`.

**Definition**

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

**Request Keys**

| Key                   | Type    | Default | Description                                                                |
| --------------------- | ------- | ------- | -------------------------------------------------------------------------- |
| `title` \*            | string  | –       | The name of the `Tag`.                                                     |
| `color` \*            | string  | –       | The color code (HEX) for the `Tag`.                                        |
| `tag_group_ids`       | array   | –       | Array of [TagGroup](tag-groups) IDs to assign the `Tag` to.                |
| `taggable_section_id` | integer | –       | The ID of the [TaggableSection](taggable-sections) to assign the `Tag` to. |

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/administration/tags', [
    'headers' => ['Authorization' => 'Bearer {accessToken}'],
    'json' => [
        'title' => 'Urgent',
        'color' => '#ffa500',
        'tag_group_ids' => [1, 2],
        'taggable_section_id' => 3
    ],
]);
```
{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 3,
    "title": "Urgent",
    "color": "#ffa500",
    "user_id": 2,
    "created_at": "2019-06-16 14:00:00",
    "updated_at": "2019-06-16 14:00:00",
    "deleted_at": null
  }
}
```

## Update

Update an existing `Tag` by `id`.

**Definition**

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

**Request Keys**

| Key             | Type   | Description                                                 |
| --------------- | ------ | ----------------------------------------------------------- |
| `title`         | string | The name of the `Tag`.                                      |
| `color`         | string | The color code (HEX) for the `Tag`.                         |
| `tag_group_ids` | array  | Array of [TagGroup](tag-groups) IDs to assign the `Tag` to. |

**Example Request**

{% tabs %}
{% tab title="PHP" %}
```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/administration/tags/3', [
    'headers' => ['Authorization' => 'Bearer {accessToken}'],
    'json' => [
        'color' => '#ffb700'
    ],
]);
```
{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 3,
    "title": "Urgent",
    "color": "#ffb700",
    "user_id": 2,
    "created_at": "2019-06-16 14:00:00",
    "updated_at": "2019-06-16 14:30:00",
    "deleted_at": null
  }
}
```

## Delete

Delete an existing `Tag` by `id`.

**Definition**

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

**Example Request**

{% tabs %}
{% tab title="PHP" %}
```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('DELETE', '/api/administration/tags/3', [
    'headers' => ['Authorization' => 'Bearer {accessToken}'],
]);
```
{% endtab %}
{% endtabs %}

**Example Response**

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