# Assign case

### Description

This service allows an operator to assign a case to another specific operator (via email) or to a defined operator group (via group name).

***

### Request

#### Restrictions

* Authentication: Requires a successful operator login.
* Mutual Exclusivity: Both an `email` and a `groupName` can't be provided in the same request. A single one must be chosen and sent as an identifier.

#### Endpoint

```
PUT https://<server-url>/api/v4/cases/{caseInstanceId}/assignment
```

#### Path Parameters

| **Parameter**    | **Type** | **Description**                                    |
| ---------------- | -------- | -------------------------------------------------- |
| `caseInstanceId` | Integer  | The unique ID of the case instance to be assigned. |

#### Parameters

| **Parameter**  | **Location**   | **Description**                                                                    |
| -------------- | -------------- | ---------------------------------------------------------------------------------- |
| `touchpoint`   | Query / Header | The identifier for the touchpoint. Use `Thalamus-Touchpoint` for the header.       |
| `token`        | Query / Header | The authentication token for the API session. Use `Thalamus-Token` for the header. |
| `Content-Type` | Header         | Must be `application/json`.                                                        |

#### Request Body

The body must contain either the `email` of the target operator or the `groupName` of the target group.

| **Field**   | **Type** | **Description**                                                         |
| ----------- | -------- | ----------------------------------------------------------------------- |
| `email`     | String   | The email address of the operator to whom the case will be assigned.    |
| `groupName` | String   | The name of the case operator group to which the case will be assigned. |

Example 1: Assign to Operator

```
{   
 "email": "operator2@thalamuscorp.com"
}
```

Example 2: Assign to Group

```
{   
 "groupName": "Local Support"
}
```

***

### Response

#### ✅ Successful Response: `201 Created`

The assignment was successful. The response returns the session `context` and the `case` object.

JSON

```
{  
   "context": {  
      "simpleProfile": {  
         "firstname": "test",
         "email": "test@test.com"
      }
   },
   "case": {  
      "id": 10,
      "categoryCode": "Reclamo", 
      "typeCode": "Telefonico", 
      "status": "resolved",
      "resolution": "Tecnica"
   }
}
```

***

### ❌ Unsuccessful Response

#### `400 Bad Request`

| **Error Code**     | **Description**                                                                              |
| ------------------ | -------------------------------------------------------------------------------------------- |
| `invalidId`        | The `caseInstanceId` is invalid, or the authenticated operator/touchpoint is not authorized. |
| `operatorNotValid` | The operator associated with the provided `email` does not exist or is invalid.              |
| `invalidName`      | The provided `groupName` does not exist.                                                     |
| `isNotAuthorized`  | The target operator is not authorized to handle this specific case type.                     |
| `blocked`          | The target operator is currently blocked in the system.                                      |
| `invalid`          | Both `email` and `groupName` were sent; they are mutually exclusive.                         |
| `missing`          | Neither `email` nor `groupName` was provided in the request body.                            |
