# Create case

### Description

This service creates a new support or administrative case for the currently logged-in party. It allows for the categorization of the case, setting initial status/resolution, and attaching custom data fields.

***

### Request

#### Restrictions

* Authentication: Requires a successful party login.
* Authorization: The touchpoint or operator must be authorized to create cases within the specified category.

#### Endpoint

```
POST https://<server-url>/api/v4/cases
```

#### 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 defines the case classification and any associated custom data.

| **Field**      | **Type** | **Description**                                                              |
| -------------- | -------- | ---------------------------------------------------------------------------- |
| `categoryCode` | String   | Required. The code for the case category (e.g., "Reclamo").                  |
| `typeCode`     | String   | Required. The specific type within the category (e.g., "Telefonico").        |
| `status`       | String   | The initial status of the case (e.g., "Created").                            |
| `resolution`   | String   | The initial resolution state (e.g., "Resolved").                             |
| `comments`     | Array    | Optional. An array of comment objects to be added upon creation.             |
| `caseData`     | Object   | Optional. A dictionary of custom fields (Boolean, Decimal, Number, or Date). |
| `attachements` | Array    | Optional. An array for file attachments associated with the case.            |

> Note on Date Formats: Custom date fields within `caseData` must be sent as a Unix timestamp string or in the format `YYYY-MM-DD`.

Example Body:

```
{
    "categoryCode": "Case6534",
    "typeCode": "Casetype6534",
    "status": "Created",
    "resolution": "Resolved",
    "comments": [],
    "caseData": {
        "Boolean6534": false,
        "Decimal6534": 10.10,
        "Date6534": "1900-02-10",
        "Number6534": 10
    },
    "attachements": []
}
```

***

### Response

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

Returns the standard session `context` and the newly created `case` object, including its unique ID.

JSON

```
{  
   "context": {  
      "simpleProfile": {  
         "firstname": "test",
         "email": "test@test.com"
      }
   },
   "case": {  
      "id": 10,
      "categoryCode": "Reclamo", 
      "typeCode": "Telefonico", 
      "status": "Open",
      "resolution": "Tecnica",
      "comments": [  
         {  
            "caseInstanceId": 10,
            "description": "This is a comment"
         }
      ]
   }
}
```

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

The following error codes may be returned in the `errors` object:

| **Error Code**             | **Description**                                                                        |
| -------------------------- | -------------------------------------------------------------------------------------- |
| `CodeRequired`             | The `categoryCode` was missing from the request.                                       |
| `InvalidCode`              | The category or type code is incorrect, or the touchpoint is not authorized to use it. |
| `InvalidName`              | The provided `status` or `resolution` name is invalid.                                 |
| `InitialStatusNotSelected` | A valid initial status was not provided.                                               |
| `CategorySystemNode`       | The category code belongs to a system node and cannot be used for new cases.           |
