PHPackages                             zammad/zammad-api-client-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. zammad/zammad-api-client-php

ActiveLibrary[API Development](/categories/api)

zammad/zammad-api-client-php
============================

Zammad API client for PHP

2.3.0(3w ago)63274.4k—4.3%26[44 issues](https://github.com/zammad/zammad-api-client-php/issues)[1 PRs](https://github.com/zammad/zammad-api-client-php/pulls)4AGPL-3.0PHPPHP &gt;=7.2CI passing

Since Oct 13Pushed 1w ago13 watchersCompare

[ Source](https://github.com/zammad/zammad-api-client-php)[ Packagist](https://packagist.org/packages/zammad/zammad-api-client-php)[ Docs](https://github.com/zammad/zammad-api-client-php)[ RSS](/packages/zammad-zammad-api-client-php/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (32)Used By (4)

Zammad API Client for PHP
=========================

[](#zammad-api-client-for-php)

This client can be used to access the API of the open source helpdesk [Zammad](http://www.zammad.org) via PHP.

Zammad version support
----------------------

[](#zammad-version-support)

This client supports Zammad 3.4.1 and newer.

Installation
------------

[](#installation)

### Requirements

[](#requirements)

The API client needs [composer](https://getcomposer.org/). For installation have a look at its [documentation](https://getcomposer.org/download/). Additionally, the API client needs PHP 7.2 or newer.

### Integration into your project

[](#integration-into-your-project)

Add the following to the "require" section of your project's composer.json file:

```
"zammad/zammad-api-client-php": "^2.3"
```

### Installing the API client's dependencies

[](#installing-the-api-clients-dependencies)

Fetch the API client's code and its dependencies by updating your project's dependencies with composer:

```
$ composer update

```

Once installed, you have to include the generated autoload.php into your project's code:

```
require_once dirname(__DIR__).'/vendor/autoload.php';
```

How to use the API client
-------------------------

[](#how-to-use-the-api-client)

### Example code

[](#example-code)

You can find example code within the directory `examples`.

### The Client object

[](#the-client-object)

Your starting point is the `Client` object:

```
use ZammadAPIClient\Client;
$client = new Client([
    'url'           => 'https://myzammad.com', // URL to your Zammad installation
    'username'      => 'myuser@myzammad.com',  // Username to use for authentication
    'password'      => 'mypassword',           // Password to use for authentication
    // 'timeout'       => 15,                  // Sets timeout for requests, defaults to 5 seconds, 0: no timeout
    // 'debug'         => true,                // Enables debug output
    // 'verify'        => true,                // Enabled SSL verification. You can also give a path to a CA bundle file. Default is true.
]);
```

Besides using a combination of `username` and `password`, you can alternatively give an `http_token` or an `oauth2_token`. **Important:** You have to activate API access in Zammad. Should be active by default.

### Fetching a single Resource object

[](#fetching-a-single-resource-object)

To fetch a `Resource` object by ID, e. g. a ticket with ID 34, use the `Client` object:

```
use ZammadAPIClient\ResourceType;
$ticket = $client->resource( ResourceType::TICKET )->get(34);
```

`$ticket` now is a `Resource` object which holds the data of the ticket and provides all of the methods for setting/getting specific values (like the title of the ticket) and sending changed values to Zammad to update the ticket.

Note: Once you successfully called `get` on a `Resource` object, you cannot call it again, instead you have to create a new one with `resource`.

### Accessing values of Resource objects

[](#accessing-values-of-resource-objects)

You can access the values of a `Resource` object via its 'value' methods.

```
$ticket->setValue( 'title', 'My ticket title' );
$title = $ticket->getValue('title');
$all_values = $ticket->getValues();
```

Please note that the API client does not provide checks for nor does it know about the available fields of the `Resource` objects. If you set or get a value of a non-existing field or set an invalid value, Zammad will ignore it or return an error.

So, how can you know which fields are available? Just fetch an existing `Resource` object and have a look at the returned fields. A fresh Zammad system always contains an object with ID 1 for every resource type.

Additionally you can have a look at the REST interface documentation of Zammad:

[Introduction to the REST interface](https://docs.zammad.org/en/latest/api/intro.html)

- [Users](https://docs.zammad.org/en/latest/api/user.html)
- [Groups](https://docs.zammad.org/en/latest/api/group.html)
- [Organizations](https://docs.zammad.org/en/latest/api/organization.html)
- [Tickets](https://docs.zammad.org/en/latest/api/ticket.html)
    - [Ticket articles](https://docs.zammad.org/en/latest/api/ticket/articles.html)
    - [Ticket priorities](https://docs.zammad.org/en/latest/api/ticket-priority.html)
    - [Ticket states](https://docs.zammad.org/en/latest/api/ticket-state.html)
- [Tags](https://docs.zammad.org/en/latest/api/tags.html)
- [Tag list](https://docs.zammad.org/en/latest/api/ticket/tags.html#administration-scope)
- [Linking Tickets](https://docs.zammad.org/en/latest/api/ticket/links.html)

#### Fetching a ticket's articles

[](#fetching-a-tickets-articles)

If you already have a ticket object, you can easily fetch its articles:

```
$ticket_articles = $ticket->getTicketArticles();
```

#### Fetching content of ticket article attachments

[](#fetching-content-of-ticket-article-attachments)

The content of ticket article attachments can be fetched with a call of `getAttachmentContent()` of the ticket article resource object:

```
$attachment_content = $ticket_article->getAttachmentContent(23);
```

In the above example 23 is the ID of the attachment. This ID can be found within the `attachments` array of the ticket article data. Usually you want to loop over this array to fetch the content of all attachments.

`getAttachmentContent()` returns the attachment content as a string, ready to use.

### Updating Resource objects

[](#updating-resource-objects)

If you fetched a `Resource` object and changed some values, you have to send your changes to Zammad. You do this with a simple call:

```
$ticket->save();
```

`save()` will check it itself but if you somehow need to know if a `Resource` object has unsaved changes, you can check it with:

```
if ( $ticket->isDirty() ) {...}
```

Note: Some resource types don't support updating the values of certain fields. Please refer to the API documentation (see links above).

### Creating Resource objects

[](#creating-resource-objects)

To create a new `Resource` object, use the following code (example):

```
use ZammadAPIClient\ResourceType;

$ticket = $client->resource( ResourceType::TICKET );
$ticket->setValue( 'title', 'My new ticket' );
// ...
// Set additional values
// ...
$ticket->save(); // Will create a new ticket object in Zammad
```

### Searching Resource objects

[](#searching-resource-objects)

Some types of resources can be searched, pagination is available.

```
use ZammadAPIClient\ResourceType;

// Fulltext search
$tickets = $client->resource( ResourceType::TICKET )->search('some text');

// Field specific search
$tickets = $client->resource( ResourceType::TICKET )->search('title:My Title');

// Field specific search with more than one field
$tickets = $client->resource( ResourceType::TICKET )->search('title:My Title AND priority_id:1');

// Pagination: Page 1, 25 entries per page
$tickets = $client->resource( ResourceType::TICKET )->search( 'some text', 1, 25 );
```

Note that there is a configurable server-side limit for the number of returned objects (e. g. 500). This limit also applies to the number of entries per page. If you call search() with 1000 entries per page and the server-side limit is set to 500, the server-side limit will be applied.

A successful search (which might have zero results) returns an array of objects (or an empty array). If the result is the original caller object, there was an error (see error handling below). Therefore, the code for searching should look like the following:

```
use ZammadAPIClient\ResourceType;

$tickets = $client->resource( ResourceType::TICKET )->search('some text');
if ( !is_array($tickets) ) {
    // Error handling
    print $tickets->getError();
}
else {
    // Do something with $tickets array
}
```

Note: You cannot use a `Resource` object that contains data (either via `get`, `search`, `all` or by setting values on a new object) to execute a search. Use a new `Resource` object instead.

### Fetching 'all' Resource objects

[](#fetching-all-resource-objects)

For some types of resources, all available objects can be fetched, pagination is available.

```
use ZammadAPIClient\ResourceType;

// Fetch all tickets (keep in mind the server-side limit, see 'Searching Resource objects')
$tickets = $client->resource( ResourceType::TICKET )->all();

// Fetch all tickets with pagination (keep in mind the server-side limit, see 'Searching Resource objects'), page 4, 50 entries per page
$tickets = $client->resource( ResourceType::TICKET )->all( 4, 50 );
```

A successful call of `all` (which might have zero results) returns an array of objects (or an empty array). If the result is the original caller object, there was an error (see error handling below). Therefore, the code to use `all` should look like the following:

```
use ZammadAPIClient\ResourceType;

$tickets = $client->resource( ResourceType::TICKET )->all( 4, 50 ); // pagination
if ( !is_array($tickets) ) {
    // Error handling
    print $tickets->getError();
}
else {
    // Do something with $tickets array
}
```

Note: You cannot use a `Resource` object that contains data (either via `get`, `search`, `all` or by setting values on a new object) to execute `all`. Use a new `Resource` object instead.

### Deleting a Resource object

[](#deleting-a-resource-object)

To be able to delete a `Resource` object that exists in Zammad, you must first fetch it from Zammad, either via `get`, `all` or `search`. You can also delete a newly created `Resource` object that has not been sent to Zammad yet. But this should only rarely be necessary because you can simply create a new `Resource` object via the `Client` object. To delete a `Resource` object, simply call `delete` on it:

```
$ticket->delete();
```

This clears the object from all data and if possible deletes it in Zammad. The PHP object itself remains. You can reuse it for another `Resource` object or simply drop it.

### Working with tags

[](#working-with-tags)

#### Adding a tag to an object

[](#adding-a-tag-to-an-object)

Zammad can assign tags to an object. Currently this is only supported for ticket objects.

```
use ZammadAPIClient\ResourceType;

// The third parameter 'Ticket' is the object type for which the ID will be given as first parameter.
$client->resource( ResourceType::TAG )->add( $ticket_id, 'tag 1', 'Ticket' );
```

#### Remove a tag from an object

[](#remove-a-tag-from-an-object)

```
use ZammadAPIClient\ResourceType;

$client->resource( ResourceType::TAG )->remove( $ticket_id, 'tag 1', 'Ticket' );
```

#### Getting all tags assigned to an object

[](#getting-all-tags-assigned-to-an-object)

```
use ZammadAPIClient\ResourceType;

// The second parameter 'Ticket' is the object type for which the ID will be given as first parameter.
$tag = $client->resource( ResourceType::TAG )->get( $ticket_id, 'Ticket' );

// [ 'tag 1', 'tag 2' ]
$tags = $tag->getValue('tags')
```

#### Search for Tags

[](#search-for-tags)

```
use ZammadAPIClient\ResourceType;

$tags = $client->resource( ResourceType::TAG )->search('my tag');
```

### Linking Tickets

[](#linking-tickets)

#### Linking two Tickets

[](#linking-two-tickets)

Zammad can link two or more Ticket objects. Allowed Link Types are `normal`, `parent` or `child`.

```
use ZammadAPIClient\ResourceType;

// First parameter $sourceTicket is the Ticket that should be linked
// Second parameter $targetTicket is the Ticket that $sourceTicket should be linked to
// Third parameter is the LinkType the $sourceTicket will be linked to $targetTicket with.
$client->resource( ResourceType::LINK )->add( $sourceTicket, $targetTicket, 'normal' );
```

### Object import

[](#object-import)

Besides the usual methods available for objects, there is also a method available to import these via CSV. Example for text module CSV import:

```
use ZammadAPIClient\ResourceType;

$text_modules_csv_string = file_get_contents('text_modules.csv');

$client->resource( ResourceType::TEXT_MODULE )->import($text_modules_csv_string);
```

See **Available resource types and their access methods** below for resource types that support CSV import.

### Handling Zammad errors

[](#handling-zammad-errors)

When you access Zammad, you **always** will get a `Resource` object (or an array of such objects) in return, regardless if Zammad returned data or executed your request. In case of errors (e. g. that above ticket with ID 34 does not exist in Zammad), you will get a `Resource` object with a set error which can be checked with the following code:

```
if ( $ticket->hasError() ) {
    print $ticket->getError();
}
```

If you additionally need more detailed information about connection/request errors, you can access the `Response` object of the `Client` object. It holds the response of the last request that was made.

```
$last_response = $client->getLastResponse();
```

With this object, you can e. g. get the HTTP status code and the body of the last response.

### Executing an API call on behalf of another user

[](#executing-an-api-call-on-behalf-of-another-user)

If you want Zammad to execute an API call on behalf of another user than the one you used for authentication, use the following code before executing the API call(s):

```
$client->setOnBehalfOfUser('myuser');
```

This sets the `From` HTTP header. Any API call after above code will use this setting. If you want to return to using the user you used for authentication, call:

```
$client->unsetOnBehalfOfUser();
```

Using this setting will be ignored by Zammad before version 2.4.

Available resource types and their access methods
-------------------------------------------------

[](#available-resource-types-and-their-access-methods)

To be able to use the 'short form' for the resource type, add a

```
use ZammadAPIClient\ResourceType;
```

to your code. You then can reference the resource type like

```
$client->resource( ResourceType::TICKET );
```

Resource typegetallsearchsavedeleteaddremoveimportTICKET✔✔✔✔✔–––TICKET\_ARTICLE✔–✔✔✔–––TICKET\_STATE✔✔–✔✔–––TICKET\_PRIORITY✔✔–✔✔–––TEXT\_MODULE✔✔–✔✔––✔ORGANIZATION✔✔✔✔✔––✔GROUP✔✔–✔✔–––USER✔✔✔✔✔––✔TAG✔✔✔✔✔✔✔–LINK✔––––✔✔–Publishing
----------

[](#publishing)

1. Add release to [CHANGELOG.md](CHANGELOG.md)
2. Commit, tag and push.
3. As a logged-in user, use the "update" button on the [packagist.org page of zammad-api-client-php](https://packagist.org/packages/zammad/zammad-api-client-php) to create the new version automatically from the git tag.

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome on [GitHub](https://github.com/zammad/zammad-api-client-php). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

### Running tests

[](#running-tests)

Tests require a running Zammad instance with API access enabled. Set the following environment variables:

VariableRequiredDefaultDescription`ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_URL`Yes—URL to Zammad (e.g. `http://localhost:3000/`)`ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_USERNAME`Yes—Username for authentication`ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_PASSWORD`Yes—Password for authentication`ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_TIMEOUT`No`30`Request timeout in seconds**Note:** Only username/password authentication is supported for tests.

```
ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_URL="http://localhost:3000/" \
ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_USERNAME="admin@example.com" \
ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_PASSWORD="test" \
ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_TIMEOUT=120 \
vendor/bin/phpunit
```

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity51

Moderate usage in the ecosystem

Community35

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~141 days

Recently: every ~321 days

Total

26

Last Release

24d ago

Major Versions

1.6.1 → 2.0.02020-09-30

PHP version history (2 changes)1.0.0PHP &gt;=5.6

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/584e58210afc2481b83a5cbb98c734c82b1d2e1bcd860ff7a3d12075a182a42c?d=identicon)[zammad](/maintainers/zammad)

![](https://www.gravatar.com/avatar/b935c2a6adb810b552592a4333b5d04795fb1beae6a7f626753ede3b008d58bb?d=identicon)[René Reimann](/maintainers/Ren%C3%A9%20Reimann)

---

Top Contributors

[![jepf](https://avatars.githubusercontent.com/u/889421?v=4)](https://github.com/jepf "jepf (39 commits)")[![mgruner](https://avatars.githubusercontent.com/u/211281?v=4)](https://github.com/mgruner "mgruner (25 commits)")[![derpixler](https://avatars.githubusercontent.com/u/809219?v=4)](https://github.com/derpixler "derpixler (22 commits)")[![melroy89](https://avatars.githubusercontent.com/u/628926?v=4)](https://github.com/melroy89 "melroy89 (4 commits)")[![MrGeneration](https://avatars.githubusercontent.com/u/6549061?v=4)](https://github.com/MrGeneration "MrGeneration (3 commits)")[![simonhammes](https://avatars.githubusercontent.com/u/10352679?v=4)](https://github.com/simonhammes "simonhammes (2 commits)")[![martini](https://avatars.githubusercontent.com/u/110226?v=4)](https://github.com/martini "martini (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![MTEXX](https://avatars.githubusercontent.com/u/3194660?v=4)](https://github.com/MTEXX "MTEXX (2 commits)")[![rocramer](https://avatars.githubusercontent.com/u/4487988?v=4)](https://github.com/rocramer "rocramer (1 commits)")[![Spice-King](https://avatars.githubusercontent.com/u/590498?v=4)](https://github.com/Spice-King "Spice-King (1 commits)")[![Axiome974](https://avatars.githubusercontent.com/u/86370894?v=4)](https://github.com/Axiome974 "Axiome974 (1 commits)")[![zkrapavickas](https://avatars.githubusercontent.com/u/15364744?v=4)](https://github.com/zkrapavickas "zkrapavickas (1 commits)")[![chii0815](https://avatars.githubusercontent.com/u/24638906?v=4)](https://github.com/chii0815 "chii0815 (1 commits)")[![jacques](https://avatars.githubusercontent.com/u/2543?v=4)](https://github.com/jacques "jacques (1 commits)")[![jaytaph](https://avatars.githubusercontent.com/u/241458?v=4)](https://github.com/jaytaph "jaytaph (1 commits)")[![lxlang](https://avatars.githubusercontent.com/u/7984421?v=4)](https://github.com/lxlang "lxlang (1 commits)")[![mantas](https://avatars.githubusercontent.com/u/36944?v=4)](https://github.com/mantas "mantas (1 commits)")[![mostafaqanbaryan](https://avatars.githubusercontent.com/u/94293456?v=4)](https://github.com/mostafaqanbaryan "mostafaqanbaryan (1 commits)")[![obuchmann](https://avatars.githubusercontent.com/u/3889302?v=4)](https://github.com/obuchmann "obuchmann (1 commits)")

---

Tags

apizammad

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zammad-zammad-api-client-php/health.svg)

```
[![Health](https://phpackages.com/badges/zammad-zammad-api-client-php/health.svg)](https://phpackages.com/packages/zammad-zammad-api-client-php)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[resend/resend-php

Resend PHP library.

617.2M43](/packages/resend-resend-php)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

563.6M13](/packages/checkout-checkout-sdk-php)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

783.8k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
