# PHP SDK

Install dimmi/dimmi-php to call the REST API, paginate lists, verify webhooks, and sign identity tokens in PHP.

`dimmi/dimmi-php` requires PHP 8.2 or later. Building with Laravel? Install the [Laravel SDK](/developers/sdks/laravel/) instead, which bundles this client plus Blade and routing helpers.

```bash
composer require dimmi/dimmi-php
```

## Create a client and make a call

```php title="dimmi.php"
<?php

require __DIR__ . '/vendor/autoload.php';

$dimmi = new Dimmi\Client(token: getenv('DIMMI_TOKEN'));

try {
    $contact = $dimmi->contacts->store(['email' => 'ada@example.com', 'name' => 'Ada Lovelace']);
    echo $contact['data']['id'], "\n";
} catch (Dimmi\ValidationException $e) {
    print_r($e->fields);
} catch (Dimmi\DimmiException $e) {
    echo $e->status, ' ', $e->errorCode, "\n";
}

foreach ($dimmi->paginate('/conversations', ['filter[status]' => 'open']) as $conversation) {
    echo $conversation['id'], "\n";
}
```

Set `DIMMI_TOKEN` to your [API token](/developers/api/authentication/). If you self-host, pass `baseUrl:` or set `DIMMI_BASE_URL`.

## Three ways to call any endpoint

Every operation in the [API reference](/api-reference/) returns a decoded JSON array and can be called three ways:

| Style | Example |
| --- | --- |
| **Resource method** | `$dimmi->conversations->messages->store($id, ['body' => 'Hello'])` |
| **Operation ID** | `$dimmi->call('conversations.messages.store', path: [$id], body: ['body' => 'Hello'])` |
| **Raw HTTP** | `$dimmi->request('POST', "/conversations/{$id}/messages", body: ['body' => 'Hello'])` |

Resource names map camelCase operation IDs (for example, `webhook-endpoints.tests.store` is `$dimmi->webhookEndpoints->tests->store()`). Arguments follow the order: path parameters, `$body` (on writes), `$query`, and `$options`.

## Paginate lists

- **`paginate()`:** yields each item across cursor-paginated endpoints (`meta.next_cursor`), fetching 100 items per page unless you set `limit`.
- **`pages()`:** yields each page across page-numbered endpoints.

Both accept a path or an operation ID, such as `$dimmi->paginate('conversations.messages.index', params: [$id])`.

## Exceptions

Every exception extends `Dimmi\DimmiException`, which exposes `status`, `errorCode`, and `fields`:

| HTTP status | Exception class |
| --- | --- |
| 400, 422 | `Dimmi\ValidationException` |
| 401 | `Dimmi\AuthenticationException` |
| 403 | `Dimmi\PermissionDeniedException` |
| 404 | `Dimmi\NotFoundException` |
| 429 | `Dimmi\RateLimitException` (includes `retryAfter` in seconds) |
| 500+ | `Dimmi\ServerException` |

## Retries and idempotency

The client retries `429`, `503`, and connection failures up to 2 times while honoring `Retry-After`. It attaches an [`Idempotency-Key`](/developers/api/idempotency/) to every `POST` and reuses it on retries.

```php
$dimmi = new Dimmi\Client(options: ['maxRetries' => 5, 'timeout' => 10, 'maxRetryDelay' => 30]);

$dimmi->contacts->store(['email' => 'ada@example.com'], options: ['idempotencyKey' => 'signup-4821']);
```

## Webhooks and identity tokens

Use `Dimmi\Webhook` for [webhook signature checks](/developers/webhooks/verify-signatures/) and `Dimmi\Identity::sign()` to sign JWTs for [identity verification](/developers/messenger/identity-verification/).

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
