PHP code example of zammad / zammad-api-client-php
1. Go to this page and download the library: Download zammad/zammad-api-client-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zammad / zammad-api-client-php example snippets
use ZammadAPIClient\Core\Auth;
use ZammadAPIClient\ZammadClient;
$client = ZammadClient::create('https://zammad.example', Auth::token('your-token'));
use ZammadAPIClient\Core\Auth;
use ZammadAPIClient\ZammadClient;
// The URL is normalized — /api/v1 is appended automatically
$client = ZammadClient::create('https://zammad.example', Auth::token('your-token'));
$client->role()->create(new RoleDTO(
name: 'Supervisor',
permission_ids: [10, 11],
group_ids: [1 => 'full'], // map of group ID to access level, agent roles only
));
use ZammadAPIClient\Core\Auth;
use ZammadAPIClient\Core\ConnectionConfig;
use ZammadAPIClient\ZammadClient;
// Token — sends Authorization: Token token=your-token (Zammad personal access token)
$client = ZammadClient::create($url, Auth::token('your-token'));
// OAuth2 — sends Authorization: Bearer your-oauth-token (OAuth2 access token)
$client = ZammadClient::create($url, Auth::oauth2('your-oauth-token'));
// Basic Auth — sends Authorization: Basic base64(user:pass)
$client = ZammadClient::create($url, Auth::basic('[email protected]', 'test'));
// Options
$client = ZammadClient::create($url, Auth::token('your-token'),
new ConnectionConfig(verifySsl: false, maxRetries: 5),
);
// Pass a PSR-3 Logger to log HTTP requests and retries
$client = ZammadClient::create($url, Auth::token('your-token'),
new ConnectionConfig(logger: $myLogger),
);
use ZammadAPIClient\Core\Transport\RequestHandler;
$handler = new RequestHandler($psr18Client, $psr17Factory, $url, auth: Auth::token('your-token'));
$client = new ZammadClient($handler);
use ZammadAPIClient\ZammadClient;
class TicketController
{
public function __construct(private ZammadClient $zammad) {}
public function show(int $id)
{
return $this->zammad->ticket()->find($id);
}
}
// Or resolve manually: app(ZammadClient::class)
use ZammadAPIClient\ZammadClient;
class TicketService
{
public function __construct(private ZammadClient $zammad) {}
public function findTicket(int $id)
{
return $this->zammad->ticket()->find($id);
}
}
// Example: reassign ticket and leave an internal note
$client->ticket()->patch(42, new TicketUpdateDTO(
owner_id: 7,
note: 'Reassigned from support queue.',
));
use ZammadAPIClient\Core\Auth;
use ZammadAPIClient\Core\Transport\ImpersonationHandler;
use ZammadAPIClient\ZammadClient;
$client = ZammadClient::create('https://zammad.example', Auth::token('your-token'));
// Accepts user ID (int), login, or email (string); no credentials needed here —
// they come from $client's handler
$asUser = new ZammadClient(new ImpersonationHandler($client->getHandler(), 1));
$ticket = $asUser->ticket()->find(42);
$asAgent = new ZammadClient(new ImpersonationHandler($client->getHandler(), '[email protected]'));
// $client itself is unaffected