# OTOBO API PHP examples

> PHP examples for the OTOBO API with cURL, a bearer token, and JSON. No Composer package required.

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

Call the OTOBO API from PHP with cURL. There is no Composer 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/).

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

## Search the FAQ

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

```php
<?php
$ch = curl_init("https://helpdesk.example.com/otobo/otai-api.pl/v1/faqs?query=vpn&limit=20");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer YOUR_TOKEN",
        "Accept: application/json",
        "Content-Type: application/json",
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $body;
```

## List queues

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

```php
<?php
$ch = curl_init("https://helpdesk.example.com/otobo/otai-api.pl/v1/queues");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer YOUR_TOKEN",
        "Accept: application/json",
        "Content-Type: application/json",
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $body;
```

## List agents

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

```php
<?php
$ch = curl_init("https://helpdesk.example.com/otobo/otai-api.pl/v1/agents");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer YOUR_TOKEN",
        "Accept: application/json",
        "Content-Type: application/json",
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $body;
```

## Find a customer user

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

```php
<?php
$ch = curl_init("https://helpdesk.example.com/otobo/otai-api.pl/v1/customer-users?search=max@example.com");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer YOUR_TOKEN",
        "Accept: application/json",
        "Content-Type: application/json",
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $body;
```

## Frequently asked questions

### Do I need a PHP 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 PHP with cURL. There is no Composer 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.

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