# OTOBO API TypeScript examples

> TypeScript examples for the OTOBO API using fetch, a bearer token, and JSON. No npm SDK required.

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

Call the OTOBO API from TypeScript with `fetch`. There is no npm package to publish for this API. 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/).

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

## Search the FAQ

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

```typescript
const response = await fetch("https://helpdesk.example.com/otobo/otai-api.pl/v1/faqs?query=vpn&limit=20", {
  method: "GET",
  headers: {
    Authorization: "Bearer YOUR_TOKEN",
    Accept: "application/json",
  },
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

## List queues

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

```typescript
const response = await fetch("https://helpdesk.example.com/otobo/otai-api.pl/v1/queues", {
  method: "GET",
  headers: {
    Authorization: "Bearer YOUR_TOKEN",
    Accept: "application/json",
  },
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

## List agents

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

```typescript
const response = await fetch("https://helpdesk.example.com/otobo/otai-api.pl/v1/agents", {
  method: "GET",
  headers: {
    Authorization: "Bearer YOUR_TOKEN",
    Accept: "application/json",
  },
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

## Find a customer user

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

```typescript
const response = await fetch("https://helpdesk.example.com/otobo/otai-api.pl/v1/customer-users?search=max@example.com", {
  method: "GET",
  headers: {
    Authorization: "Bearer YOUR_TOKEN",
    Accept: "application/json",
  },
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

## Frequently asked questions

### Do I need a TypeScript 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 TypeScript with fetch. There is no npm package to publish for this API. The examples below are the whole client: a bearer token and JSON.

- [OTOBO API TypeScript examples](https://otobo-docs.softoft.de/en/otobo-api/typescript/)
- [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 TypeScript examples](https://otobo-docs.softoft.de/en/otobo-api/typescript/)
- [OTOBO Admin Manual](https://doc.otobo.org/manual/admin/11.0/en/content/index.html)
