> For the complete documentation index, see [llms.txt](https://mava.gitbook.io/mava-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mava.gitbook.io/mava-docs/webhooks-and-api/api/update-ticket.md).

# Update Ticket

### Endpoint

```
PUT /api/ticket
```

### Authentication

* Requires API token authentication
* Subject to rate limiting

### Request Body

| Field        | Type   | Required | Description                         |
| ------------ | ------ | -------- | ----------------------------------- |
| `ticketId`   | string | Yes      | The unique identifier of the ticket |
| `status`     | string | No       | New ticket status                   |
| `priority`   | number | No       | New priority level                  |
| `categoryId` | string | No       | ID of the category to assign        |
| `assignedTo` | string | No       | ID of the agent to assign           |

#### Valid Values

* **`status`**: `"Open"`, `"Resolved"`, `"Pending"`, `"Waiting"`
* **`priority`**: `1`, `2`, `3`
* **`categoryId`**: Must be a valid category ID from GET /categories
* **`assignedTo`**: The `id` of an agent from GET /agents. Omit to leave assignment unchanged, or `null` to make the ticket unassigned

> **Note:** `assignedTo` takes an agent **ID** (obtained from GET /agents), not an email address. This allows agents who signed up with a wallet — and therefore have no email — to be assigned tickets. Passing an email (or any value that is not a valid agent ID) returns a validation error.

### Response

**Success (200 OK)**

```json
{
  "message": "Ticket updated"
}
```

#### Error Responses

**Ticket not found (400)**

```json
{
  "error": "Ticket not found"
}
```

**Invalid category (400)**

```json
{
  "error": "Category not found"
}
```

**Invalid status/priority (400)**

```json
{
  "error": "Invalid status or priority"
}
```

**Assignee not found (400)**

```json
{
  "error": "Assignee not found"
}
```

**Server error (500)**

```json
{
  "error": "Internal server error"
}
```

### Behavior

* Each change (status, priority, category, assignment) creates an audit log message
* Changes only apply when new values differ from existing values
* Categories must be active and associated with the client
* `assignedTo` is resolved to an agent in your organization. An ID that does not belong to your organization is rejected with `Assignee not found`
* Assigning a ticket that the AI is actively handling ends AI handling (the ticket is handed off to the agent)

### Example (cURL)

```bash
curl -X PUT https://app.mava.app/api/ticket \
    -H "x-auth-token: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"ticketId":"TICKET_ID","assignedTo":"6630a1f4c2b9e4a1d8f00b21"}'
```
