# OTOBO API Java examples

> Java examples for the OTOBO API with HttpClient, a bearer token, and JSON. No extra library to deploy.

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

Call the OTOBO API from Java with `java.net.http.HttpClient` (Java 11 or newer). There is no library to deploy. The examples below are the whole client: a bearer token and JSON.

Replace `YOUR_TOKEN` with a token from **Admin → API** or from an agent's personal API token. The base URL on this OTOBO system is `https://helpdesk.example.com/otobo/otai-api.pl/v1`. How tokens expire and how rights follow the user is on the [authentication page](https://otobo-docs.softoft.de/en/otobo-api/authentication/).

## Create a ticket

Fields and errors: [Tickets](https://otobo-docs.softoft.de/en/otobo-api/tickets/).

```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());
```

## Search the FAQ

Fields and errors: [FAQ](https://otobo-docs.softoft.de/en/otobo-api/faq/).

```java

HttpClient client = HttpClient.newHttpClient();
HttpRequest.BodyPublisher body = HttpRequest.BodyPublishers.noBody();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://helpdesk.example.com/otobo/otai-api.pl/v1/faqs?query=vpn&limit=20"))
    .header("Authorization", "Bearer YOUR_TOKEN")
    .header("Accept", "application/json")
    .method("GET", body)
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

## List queues

Fields and errors: [Queues](https://otobo-docs.softoft.de/en/otobo-api/catalogue/).

```java

HttpClient client = HttpClient.newHttpClient();
HttpRequest.BodyPublisher body = HttpRequest.BodyPublishers.noBody();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://helpdesk.example.com/otobo/otai-api.pl/v1/queues"))
    .header("Authorization", "Bearer YOUR_TOKEN")
    .header("Accept", "application/json")
    .method("GET", body)
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

## List agents

Fields and errors: [Agents](https://otobo-docs.softoft.de/en/otobo-api/agents/).

```java

HttpClient client = HttpClient.newHttpClient();
HttpRequest.BodyPublisher body = HttpRequest.BodyPublishers.noBody();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://helpdesk.example.com/otobo/otai-api.pl/v1/agents"))
    .header("Authorization", "Bearer YOUR_TOKEN")
    .header("Accept", "application/json")
    .method("GET", body)
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

## Find a customer user

Fields and errors: [Customer users](https://otobo-docs.softoft.de/en/otobo-api/customers/).

```java

HttpClient client = HttpClient.newHttpClient();
HttpRequest.BodyPublisher body = HttpRequest.BodyPublishers.noBody();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://helpdesk.example.com/otobo/otai-api.pl/v1/customer-users?search=max@example.com"))
    .header("Authorization", "Bearer YOUR_TOKEN")
    .header("Accept", "application/json")
    .method("GET", body)
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

## Frequently asked questions

### Do I need a Java SDK for the OTOBO API?

No. The examples send HTTP with a bearer token. There is no package to publish or upgrade.

Call the OTOBO API from Java with java.net.http.HttpClient (Java 11 or newer). There is no library to deploy. The examples below are the whole client: a bearer token and JSON.

- [OTOBO API Java examples](https://otobo-docs.softoft.de/en/otobo-api/java/)
- [OTOBO Admin Manual](https://doc.otobo.org/manual/admin/11.0/en/content/index.html)

### Where do I send the token?

In the Authorization: Bearer header. The base URL ends with /otai-api.pl/v1.

- [OTOBO API Java examples](https://otobo-docs.softoft.de/en/otobo-api/java/)
- [OTOBO Admin Manual](https://doc.otobo.org/manual/admin/11.0/en/content/index.html)
