# Update case

### Description

This service updates the details of an existing case identified by its `caseInstanceId`. It allows for changing the status, resolution, and custom data associated with the case.

***

### Request

#### Restrictions

* Authentication: Requires a successful operator or party login.
* Authorization: The request may fail if the authenticated user or touchpoint does not have permission to modify the specific case.
* Mandatory Fields: `categoryCode` and `typeCode` must always be included in the request body.

> #### ⚠️ Critical Note on `caseData`
>
> When updating `caseData`, all defined fields for that case type must be included in the request, even if their values are not changing. If a field is omitted, the API will return an `invalidCaseField` error.

#### Endpoint

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

#### Path Parameters

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

#### 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

| **Field**      | **Type** | **Description**                                                                     |
| -------------- | -------- | ----------------------------------------------------------------------------------- |
| `categoryCode` | String   | Mandatory. The code for the case category.                                          |
| `typeCode`     | String   | Mandatory. The specific type within the category.                                   |
| `status`       | String   | The updated status name (e.g., "In Progress").                                      |
| `resolution`   | String   | The updated resolution name (e.g., "Resolved").                                     |
| `comments`     | Array    | Optional. An array of new comments to add to the case.                              |
| `caseData`     | Object   | Conditional. If provided, it must contain all fields associated with the case type. |

Example Body:

```
{
    "categoryCode": "Case6534",
    "typeCode": "Casetype6534",
    "status": "Created",
    "resolution": "Resolved",
    "comments": [],
    "caseData": {
        "Boolean6534": true,
        "Decimal6534": 2.2,
        "Number6534": 2500
    }
}
```

***

### Response

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

The case was successfully updated. The response returns the session `context` and the updated `case` object.

JSON

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

#### ❌ Unsuccessful Response: `400 Bad Request`

| **Error Code**       | **Description**                                                                        |
| -------------------- | -------------------------------------------------------------------------------------- |
| `invalidId`          | The `caseInstanceId` is invalid, or the user is not authorized to view/edit this case. |
| `CodeRequired`       | The `categoryCode` or `typeCode` was missing.                                          |
| `InvalidCode`        | The category or type code is incorrect.                                                |
| `InvalidName`        | The provided `status` or `resolution` name is invalid.                                 |
| `invalidCaseField`   | One or more mandatory fields within the `caseData` object are missing.                 |
| `CategorySystemNode` | The category code belongs to a system node and cannot be modified.                     |
