# OTOBO API Tickets

> Tickets über die OTOBO API mit Bearer-Token anlegen, suchen, lesen und per PATCH ändern.

- HTML: https://otobo-docs.softoft.de/de/otobo-api/tickets/
- Markdown: https://otobo-docs.softoft.de/de/otobo-api/tickets.md

Die Ticket-Routen nutzen dieselben Felder wie die Agentenoberfläche: Titel, Queue, Status, Priorität, Typ, Kundenbenutzer und den ersten Artikel.

| Aktion | Aufruf |
| --- | --- |
| Suchen und listen | `GET /tickets?queue=Service%20Desk&state=new&limit=20&offset=0` |
| Ein Ticket | `GET /tickets/42` |
| Anlegen | `POST /tickets` |
| Teiländerung | `PATCH /tickets/42` |

Suchparameter: `queue`, `state`, `priority`, `type`, `title`, `ticketNumber`, `customerUser`, `limit`, `offset`. `GET /tickets` ist die Liste. `GET /tickets/{id}` ist ein Ticket. Es gibt keinen eigenen Pfad für find oder findAll.

## Anlegen

```json
{
  "title": "Printer offline",
  "queue": "Service Desk",
  "state": "new",
  "priority": "3 normal",
  "customerUser": "max@example.com",
  "article": {
    "subject": "Printer offline",
    "body": "Floor 2, the device shows no paper path.",
    "mimeType": "text/plain"
  }
}
```

Die Antwort enthält `id` und `ticketNumber`.

## Ändern

`PATCH` sendet nur die Felder, die sich ändern.

```json
{
  "state": "open",
  "priority": "4 high"
}
```

Eine Queue, die der Benutzer des Tokens nicht schreiben darf, liefert `403`.

### Python

```python

payload = {
  "title": "Printer offline",
  "queue": "Service Desk",
  "state": "new",
  "priority": "3 normal",
  "customerUser": "max@example.com",
  "article": {
    "subject": "Printer offline",
    "body": "Floor 2, the device shows no paper path.",
    "mimeType": "text/plain"
  }
}

response = requests.post(
    "https://helpdesk.example.com/otobo/otai-api.pl/v1/tickets",
    headers={"Authorization": "Bearer YOUR_TOKEN"},,
    json=payload
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

### TypeScript

```typescript
const payload = {
  "title": "Printer offline",
  "queue": "Service Desk",
  "state": "new",
  "priority": "3 normal",
  "customerUser": "max@example.com",
  "article": {
    "subject": "Printer offline",
    "body": "Floor 2, the device shows no paper path.",
    "mimeType": "text/plain"
  }
};

const response = await fetch("https://helpdesk.example.com/otobo/otai-api.pl/v1/tickets", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_TOKEN",
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

### Java

```java

HttpClient client = HttpClient.newHttpClient();
String payload = """
        {
          "title": "Printer offline",
          "queue": "Service Desk",
          "state": "new",
          "priority": "3 normal",
          "customerUser": "max@example.com",
          "article": {
            "subject": "Printer offline",
            "body": "Floor 2, the device shows no paper path.",
            "mimeType": "text/plain"
          }
        }
        """;
HttpRequest.BodyPublisher body = HttpRequest.BodyPublishers.ofString(payload);
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://helpdesk.example.com/otobo/otai-api.pl/v1/tickets"))
    .header("Authorization", "Bearer YOUR_TOKEN")
    .header("Accept", "application/json")
    .method("POST", body)
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

### PHP

```php
<?php
$payload = <<<'JSON'
{
  "title": "Printer offline",
  "queue": "Service Desk",
  "state": "new",
  "priority": "3 normal",
  "customerUser": "max@example.com",
  "article": {
    "subject": "Printer offline",
    "body": "Floor 2, the device shows no paper path.",
    "mimeType": "text/plain"
  }
}
JSON;
$ch = curl_init("https://helpdesk.example.com/otobo/otai-api.pl/v1/tickets");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer YOUR_TOKEN",
        "Accept: application/json",
        "Content-Type: application/json",
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$body = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $body;
```

Ausführliche Beispiele, eine Sprache pro Seite:

- [Python](https://otobo-docs.softoft.de/de/otobo-api/python/)
- [TypeScript](https://otobo-docs.softoft.de/de/otobo-api/typescript/)
- [Java](https://otobo-docs.softoft.de/de/otobo-api/java/)
- [PHP](https://otobo-docs.softoft.de/de/otobo-api/php/)

Zulässige Werte für Queue, Status und Typ kommen von den [Katalog-Routen](https://otobo-docs.softoft.de/de/otobo-api/catalogue/).

## Häufig gestellte Fragen

### Welche HTTP-Methode ändert ein Ticket?

PATCH /tickets/{id} ändert nur die Felder, die Sie senden. Einen eigenen Vollersatz-Aufruf gibt es nicht.

- [OTOBO API Tickets](https://otobo-docs.softoft.de/de/otobo-api/tickets/)
- [OTOBO Admin-Handbuch](https://doc.otobo.org/manual/admin/11.0/de/content/index.html)

### Wie suche ich Tickets?

GET /tickets mit Parametern wie queue, state, title, ticketNumber, limit und offset.

Suchparameter: queue, state, priority, type, title, ticketNumber, customerUser, limit, offset. GET /tickets ist die Liste. GET /tickets/{id} ist ein Ticket. Es gibt keinen eigenen Pfad für find oder findAll.

- [OTOBO API Tickets](https://otobo-docs.softoft.de/de/otobo-api/tickets/)
- [OTOBO Admin-Handbuch](https://doc.otobo.org/manual/admin/11.0/de/content/index.html)
