# Departments

## The Department model

| Key         | Type    | Description                                                          |
| ----------- | ------- | -------------------------------------------------------------------- |
| id          | String  | The unique identifier for the department which is given by Tiledesk. |
| name        | String  | The department name.                                                 |
| id\_bot     | Array   | The bot identifier associated to the department                      |
| routing     | String  | The department routing type. Permitted values: 'assigned', 'pooled'  |
| id\_group   | String  | The group identifier associated to the department                    |
| default     | Boolean | Determines if it is the default department                           |
| status      | Number  | The request status: VISIBLE : 1, INVISIBLE : 0                       |
| attributes  | Object  | The custom attributes which are set for the department.              |
| createdAt   | String  | The time when the department was created.                            |
| updatedAt   | String  | The time when the department was updated.                            |
| createdBy   | String  | The unique identifier of the row creator                             |
| id\_project | String  | The unique identifier of the project                                 |
| groups      | Array   | The array of groups associated to the department                     |

## Get all active departments

<mark style="color:blue;">`GET`</mark> `https://api.tiledesk.com/v3/:project_id/departments`

Allows an account to list all the active departments of the project.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| project\_id | string | the Project Id is a unique code assigned to your project when you create it in Tiledesk. |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | authorization token. Basic Auth or JWT |

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

```
[
   {
      "_id":"5b55e806c93dde00143163df",
      "updatedAt":"2019-08-02T08:08:22.292Z",
      "createdAt":"2018-07-23T14:36:54.410Z",
      "name":"Default Department",
      "id_project":"5b55e806c93dde00143163dd",
      "createdBy":"5aaa99024c3b110014b478f0",
      "online_msg":"Describe shortly your problem, you will be contacted by an agent..",
      "offline_msg":"",
      "__v":0,
      "id_bot":"5be9b2ecc72a050015e14951",
      "status":1,
      "default":true,
      "routing":"assigned"
   }
]
```

{% endtab %}
{% endtabs %}

Example

```
curl -v -X GET https://api.tiledesk.com/v3/5b55e806c93dde00143163dd/departments
```

## Get all departments (active or hidden)

<mark style="color:blue;">`GET`</mark> `https://api.tiledesk.com/v3/:project_id/departments/allstatus`

Allows an account to list all the departments of the project.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| project\_id | string | the Project Id is a unique code assigned to your project when you create it in Tiledesk. |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | authorization token. Basic Auth or JWT |

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

```
[
   {
      "_id":"5b55e806c93dde00143163df",
      "updatedAt":"2019-08-02T08:08:22.292Z",
      "createdAt":"2018-07-23T14:36:54.410Z",
      "name":"Default Department",
      "id_project":"5b55e806c93dde00143163dd",
      "createdBy":"5aaa99024c3b110014b478f0",
      "online_msg":"Describe shortly your problem, you will be contacted by an agent..",
      "offline_msg":"",
      "__v":0,
      "id_bot":"5be9b2ecc72a050015e14951",
      "status":1,
      "default":true,
      "routing":"assigned"
   }
]
```

{% endtab %}
{% endtabs %}

Example

```
curl -v -X GET -u andrea.leo@f21.it:123456 https://api.tiledesk.com/v3/5b55e806c93dde00143163dd/departments/allstatus
```

## Get a department by id

<mark style="color:blue;">`GET`</mark> `https://api.tiledesk.com/v3/:project_id/departments`

Allows an account to get a department of the project.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| project\_id | string | the Project Id is a unique code assigned to your project when you create it in Tiledesk. |
| id          | string | The department identifier                                                                |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | authorization token. Basic Auth or JWT |

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

```
   {
      "_id":"5b55e806c93dde00143163df",
      "updatedAt":"2019-08-02T08:08:22.292Z",
      "createdAt":"2018-07-23T14:36:54.410Z",
      "name":"Default Department",
      "id_project":"5b55e806c93dde00143163dd",
      "createdBy":"5aaa99024c3b110014b478f0",
      "online_msg":"Describe shortly your problem, you will be contacted by an agent..",
      "offline_msg":"",
      "__v":0,
      "id_bot":"5be9b2ecc72a050015e14951",
      "status":1,
      "default":true,
      "routing":"assigned"
   }
```

{% endtab %}
{% endtabs %}

Example

```
curl -v -X GET -u andrea.leo@f21.it:123456 https://api.tiledesk.com/v3/5b55e806c93dde00143163dd/departments/5b55e806c93dde00143163df
```

## Create a new department

<mark style="color:green;">`POST`</mark> `https://api.tiledesk.com/v3/:project_id/departments`

Allows to add more departments.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| project\_id | string | The project\_id is a unique code assigned to your project when you create it in Tiledesk |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | authorization token. Basic Auth or JWT |
| Content-Type  | string | use "application/json" value           |

#### Request Body

| Name      | Type   | Description                                                                                                                      |
| --------- | ------ | -------------------------------------------------------------------------------------------------------------------------------- |
| name      | string | The department name                                                                                                              |
| routing   | string | Optional. The department routing type. Permitted values: 'assigned', 'pooled' (default)                                          |
| id\_group | string | Optional. The group of users assigned to the department. If not provided the request will be routed through all available users. |
| id\_bot   | string | Optional. The bot assigned to the department, if any.                                                                            |

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

```
 {
      "_id":"5b55e806c93dde00143163df",
      "updatedAt":"2019-08-02T08:08:22.292Z",
      "createdAt":"2018-07-23T14:36:54.410Z",
      "name":"Default Department",
      "id_project":"5b55e806c93dde00143163dd",
      "createdBy":"5aaa99024c3b110014b478f0",
      "online_msg":"Describe shortly your problem, you will be contacted by an agent..",
      "offline_msg":"",
      "__v":0,
      "id_bot":"5be9b2ecc72a050015e14951",
      "status":1,
      "default":true,
      "routing":"assigned"
   }
```

{% endtab %}
{% endtabs %}

Example:

```
curl -v -X POST -H 'Content-Type: application/json' -u andrea.leo@f21.it:123456  -d '{"name":"new department1", "routing":"pooled"}' https://api.tiledesk.com/v3/5b55e806c93dde00143163dd/departments
```

## Update a department

<mark style="color:orange;">`PUT`</mark> `https://api.tiledesk.com/v3/:project_id/departments/:id`

Allows to update a department.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| project\_id | string | The project\_id is a unique code assigned to your project when you create it in Tiledesk |
| id          | string | The department identifier                                                                |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | authorization token. Basic Auth or JWT |
| Content-Type  | string | use "application/json" value           |

#### Request Body

| Name      | Type   | Description                                                                                                                                                                              |
| --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name      | string | The department name                                                                                                                                                                      |
| routing   | string | Optional. The department routing type. Permitted values: 'assigned', 'pooled' (default)                                                                                                  |
| id\_group | string | Optional. The group of users assigned to the department. If not provided the request will be routed through all available users.                                                         |
| groups    | array  | Optional. The groups assigned to the department with the id\_group and percentage for dynamic load distribution. If not provided the request will be routed through all available users. |
| id\_bot   | string | Optional. The bot assigned to the department, if any.                                                                                                                                    |

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

```
 {
      "_id":"5b55e806c93dde00143163df",
      "updatedAt":"2019-08-02T08:08:22.292Z",
      "createdAt":"2018-07-23T14:36:54.410Z",
      "name":"Default Department",
      "id_project":"5b55e806c93dde00143163dd",
      "createdBy":"5aaa99024c3b110014b478f0",
      "online_msg":"Describe shortly your problem, you will be contacted by an agent..",
      "offline_msg":"",
      "__v":0,
      "id_bot":"5be9b2ecc72a050015e14951",
      "status":1,
      "default":true,
      "routing":"pooled",
      "groups": [
         {
            "id_group": "6877b2eb1568590013b57fde",
            "percentage": 70
         },
         {
            "id_group": "68c9156171b6b900145f117b",
            "percentage": 30
         }
      ]
   }
```

{% endtab %}
{% endtabs %}

Example:

```
curl -v -X PUT -H 'Content-Type: application/json' -u andrea.leo@f21.it:123456  -d '{"name":"new department1", "routing":"pooled", "groups": [{ "id_group": "6877b2eb1568590013b57fde", "percentage": 70 }, { "id_group": "68c9156171b6b900145f117b", "percentage": 30 }]}' https://api.tiledesk.com/v3/5b55e806c93dde00143163dd/departments/5b55e806c93dde00143163df
```

## Delete a department

<mark style="color:red;">`DELETE`</mark> `https://api.tiledesk.com/v3/:project_id/departments/:id`

Allows to delete a department.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| project\_id | string | The project\_id is a unique code assigned to your project when you create it in Tiledesk |
| id          | string | The department identifier                                                                |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | authorization token. Basic Auth or JWT |

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

```
 {
      "_id":"5b55e806c93dde00143163df",
      "updatedAt":"2019-08-02T08:08:22.292Z",
      "createdAt":"2018-07-23T14:36:54.410Z",
      "name":"Default Department",
      "id_project":"5b55e806c93dde00143163dd",
      "createdBy":"5aaa99024c3b110014b478f0",
      "online_msg":"Describe shortly your problem, you will be contacted by an agent..",
      "offline_msg":"",
      "__v":0,
      "id_bot":"5be9b2ecc72a050015e14951",
      "status":1,
      "default":true,
      "routing":"assigned"
   }
```

{% endtab %}
{% endtabs %}

Example:

```
curl -v -X DELETE -H 'Content-Type: application/json' -u andrea.leo@f21.it:123456  https://api.tiledesk.com/v3/5b55e806c93dde00143163dd/departments/5b55e806c93dde00143163df
```
