PHPackages                             codebar-ag/laravel-zammad - 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. codebar-ag/laravel-zammad

ActiveLibrary[API Development](/categories/api)

codebar-ag/laravel-zammad
=========================

Zammad integration with Laravel

v12.8.0(1mo ago)106.1k↑65%2[2 issues](https://github.com/codebar-ag/laravel-zammad/issues)[1 PRs](https://github.com/codebar-ag/laravel-zammad/pulls)MITPHPPHP 8.2.\*|8.3.\*|8.4.\*CI failing

Since Apr 21Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/codebar-ag/laravel-zammad)[ Packagist](https://packagist.org/packages/codebar-ag/laravel-zammad)[ Docs](https://github.com/codebar-ag/laravel-zammad)[ RSS](/packages/codebar-ag-laravel-zammad/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (28)Versions (37)Used By (0)

[![](https://camo.githubusercontent.com/257946337207c01de7bc505cbb5e2c88ec5aa35e19d2db123ff4c4594106bc8d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305a616d6d61642e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d636f64656261722d61672532466c61726176656c2d7a616d6d6164267061747465726e3d63697263756974426f617264267374796c653d7374796c655f32266465736372697074696f6e3d416e2b6f70696e696f6e617465642b7761792b746f2b696e746567726174652b5a616d6d61642b776974682b4c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313530707826696d616765733d7469636b6574267769647468733d35303026686569676874733d353030)](https://camo.githubusercontent.com/257946337207c01de7bc505cbb5e2c88ec5aa35e19d2db123ff4c4594106bc8d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305a616d6d61642e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d636f64656261722d61672532466c61726176656c2d7a616d6d6164267061747465726e3d63697263756974426f617264267374796c653d7374796c655f32266465736372697074696f6e3d416e2b6f70696e696f6e617465642b7761792b746f2b696e746567726174652b5a616d6d61642b776974682b4c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313530707826696d616765733d7469636b6574267769647468733d35303026686569676874733d353030)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f75f037f6242db5486162263ce30d6b51ac077602d2b0874cfa24ab1918cfa23/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64656261722d61672f6c61726176656c2d7a616d6d61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codebar-ag/laravel-zammad)[![Total Downloads](https://camo.githubusercontent.com/fdc9bdf599d428163d844104732686e4a18bb549e046914caa5e86b383896271/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64656261722d61672f6c61726176656c2d7a616d6d61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codebar-ag/laravel-zammad)[![GitHub-Tests](https://github.com/codebar-ag/laravel-zammad/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/codebar-ag/laravel-zammad/actions/workflows/run-tests.yml)[![GitHub Code Style](https://github.com/codebar-ag/laravel-zammad/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=main)](https://github.com/codebar-ag/laravel-zammad/actions/workflows/fix-php-code-style-issues.yml)[![PHPStan](https://github.com/codebar-ag/laravel-zammad/actions/workflows/phpstan.yml/badge.svg)](https://github.com/codebar-ag/laravel-zammad/actions/workflows/phpstan.yml)[![Dependency Review](https://github.com/codebar-ag/laravel-zammad/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/codebar-ag/laravel-zammad/actions/workflows/dependency-review.yml)

This package was developed to give you a quick start to communicate with the Zammad REST API. It is used to query the most common endpoints.

⚠️ This package is not designed as a replacement of the official [Zammad REST API](https://docs.zammad.org/en/latest/api/intro.html). See the documentation if you need further functionality. ⚠️

💡 What is Zammad?
-----------------

[](#-what-is-zammad)

Zammad is a web-based open source helpdesk/customer support system with many features to manage customer communication.

🛠 Requirements
--------------

[](#-requirements)

PackagePHPLaravelZammadv12.0^8.2 - ^8.4Laravel 12.0✅v11.0^8.2 - ^8.3Laravel 11.0✅v3.08.2Laravel 10.0✅v2.08.1Laravel 9.0✅v1.08.0Laravel 8.12✅⚙️ Installation
---------------

[](#️-installation)

You can install the package via composer:

```
composer require codebar-ag/laravel-zammad
```

Add the following environment variables to your `.env` file:

```
ZAMMAD_URL=https://domain.zammad.com
ZAMMAD_TOKEN=token
```

### 🔑 Where can I find the token?

[](#-where-can-i-find-the-token)

Go to your profile page in your Zammad application. In the tab **Token Access** you can create your token. Be sure to activate all rights you need.

👉 Make sure to activate **HTTP Token Authentication** in your system settings.

### 📝 How to add dynamic ticket attributes?

[](#-how-to-add-dynamic-ticket-attributes)

- Publish your configuration file (see chapter `🔧 Configuration file`).
- Add attributes to the *ticket* key:

```
'ticket' => [
    'note' => 'string',
    'additional_id' => 'integer',
],
```

🏗 Usage
-------

[](#-usage)

### 👶 User Resource

[](#-user-resource)

```
use CodebarAg\Zammad\Facades\Zammad;
```

```
/**
 * Get the current authenticated user.
 */

$user = Zammad::user()->me();
```

```
/**
 * Show a list of users.
 */

$users = Zammad::user()->list();
```

```
/**
 * Search a single user.
 */

$term = 'email:sebastian.fix@codebar.ch';

$user = Zammad::user()->search($term);
```

```
/**
 * Show a user by id.
 */

$user = Zammad::user()->show(20);
```

```
/**
 * Create a new user.
 */

$data = [
    'firstname' => 'Max',
    'lastname' => 'Mustermann',
        'email' => 'max.mustermann@codebar.ch',
];

$user = (new Zammad())->user()->create($data);
```

```
/**
 * Update a existing user.
 */

$data = [
    'firstname' => 'Max',
    'lastname' => 'Mustermann',
];

$user = (new Zammad())->user()->update($id, $data);
```

```
/**
 * Delete a user by id.
 */

(new Zammad())->user()->delete(20);
```

```
/**
 * Search a user by email. If not found create a new user.
 */

$user = (new Zammad())->user()->searchOrCreateByEmail('max.mustermann@codebar.ch');
```

```
/**
 * Search a user by email. If not found create a new user with custom $data
 */

$data = [
    'firstname' => 'Max',
    'lastname' => 'Mustermann',
    'email' => 'max.mustermann@codebar.ch',
];

$user = (new Zammad())->user()->searchOrCreateByEmail('max.mustermann@codebar.ch', $data);
```

### 🎫 Ticket Resource

[](#-ticket-resource)

```
use CodebarAg\Zammad\Facades\Zammad;
```

```
/**
 * Show a list of tickets.
 */

$tickets = Zammad::ticket()->list();
```

```
/**
 * Search tickets which include following term.
 */

$term = 'Max Mustermann';

$tickets = Zammad::ticket()->search($term);
```

```
/**
 * Show a ticket by id (empty comments).
 */

$ticket = Zammad::ticket()->show(20);
```

```
/**
 * Show a ticket by id with comments.
 */

$ticket = Zammad::ticket()->showWithComments(20);
```

```
/**
 * Create a new ticket.
 */

$data = [
    'title' => 'The application is not working',
    'group' => 'Inbox',
    'customer_id' => 20,
    // 'customer' => 'bob@domain.test', // or use the customer e-mail address
    'article' => [
        'body' => 'It just crashes if I visit the page',
        'attachments' => [
            [
                'filename' => 'log.txt',
                'data' => 'V2FzdGUgbm8gbW9yZSB0aW1lIGFyZ3Vpbmcgd2hhdCBhIGdvb2QgbWFuIHNob3VsZCBiZSwgYmUgb25l',
                'mime-type' => 'text/plain'
            ],
        ],
    ],
];

$ticket = (new Zammad())->ticket()->create($data);
```

```
/**
 * Delete a ticket by id.
 */

(new Zammad())->user()->delete(20);
```

### 💬 Comment Resource

[](#-comment-resource)

```
use CodebarAg\Zammad\Facades\Zammad;
```

```
/**
 * Show comments by ticket id
 */

$comments = Zammad::comment()->showByTicket(20);
```

```
/**
 * Show a comment by id.
 */

$comment = Zammad::comment()->show(20);
```

```
/**
 * Create a new comment.
 */

$data = [
    'ticket_id' => 42,
    'subject' => 'Login still not working',
    'body' => 'Somehow the login is not workingCould you check that?',
    'content_type' => 'text/html',
    'attachments' => [
        [
            'filename' => 'log.txt',
            'data' => 'WW91IGFyZSBhIPCfjoEgZm9yIHRoZSDwn4yN',
            'mime-type' => 'text/plain',
        ],
    ],
];

$comment = (new Zammad())->comment()->create($data);
```

```
/**
 * Delete a comment by id.
 */

(new Zammad())->comment()->delete(20);
```

### 🏠 Object Resource

[](#-object-resource)

```
use CodebarAg\Zammad\Facades\Zammad;
```

```
/**
 * Show a list of objects.
 */

$objects = Zammad::object()->list();
```

```
/**
 * Create a object
 */

 $data = [
    'title' => 'sample_boolean',
    'object' => 'Ticket',
    'display' => 'Sample Boolean',
    'active' => true,
    'position' => 1500,
    'data_type' => 'select',
    'data_option' => [
        'options' => [
            'key-one' => 'First Key',
            'key-two' => 'Second Key',
            'key-three' => 'Third Key',
        ],
        'default' => 'key-one'
    ],
];

$object = Zammad::object()->create($data);
```

```
/**
 * Update a object
 */

$object = Zammad::object()->update($id, $data);
```

```
/**
 * Show a object by id.
 */

$object = Zammad::object()->show(20);
```

```
/**
 * Execute database migrations
 */

(new Zammad())->object()->executeMigrations();
```

### 🧷 Attachment Resource

[](#-attachment-resource)

```
use CodebarAg\Zammad\Facades\Zammad;
```

```
/**
 * Download attachment.
 */
$content = Zammad::attachment()->download(
    ticketId: 32,
    commentId: 111,
    attachmentId: 42,
);
```

Expanding response payloads
---------------------------

[](#expanding-response-payloads)

You can use the `expand()` method to expand the response with additional data.

See documentation on this in the [Zammad API Docs](https://docs.zammad.org/en/latest/api/intro.html?highlight=expand#response-payloads-expand).

```
$ticket = Zammad::ticket()->expand()->show(20);
$user = Zammad::user()->expand()->show(20);
$me = Zammad::user()->expand()->me();
```

Limit search response payloads
------------------------------

[](#limit-search-response-payloads)

You can use the `limit(int $limit = 1)` method to expand the response with additional data.

See documentation on this in the [Zammad API Docs](https://docs.zammad.org/en/latest/api/user.html#search).

```
$ticket = Zammad::ticket()->limit(1)->search();
$user = Zammad::user()->limit(1)->search();
```

Paginate list response payloads
-------------------------------

[](#paginate-list-response-payloads)

You can use the `perPage(int $perPage)` and `page(int $page)` methods to set the page and per page values for the response Alternatively you can use the `paginate(int $page, int $perPage):` method to set both at once.

See documentation on this in the [Zammad API Docs](https://docs.zammad.org/en/latest/api/intro.html#pagination).

```
$ticket = Zammad::ticket()->perPage(1)->page(1)->list();
$user = Zammad::user()->perPage(1)->page(1)->list();

$ticket = Zammad::ticket()->paginate(1, 1)->list();
$user = Zammad::user()->paginate(1, 1)->list();
```

🏋️ DTO showcase
---------------

[](#️-dto-showcase)

```
CodebarAg\Zammad\DTO\User {
  +id: 20                       // int
  +first_name: "Max"            // string
  +last_name: "Mustermann"       // string
  +login: "max.mustermann@codebar.ch"     // string
  +email: "max.mustermann@codebar.ch"     // string
  +last_login_at: Carbon\Carbon // Carbon
  +updated_at: Carbon\Carbon    // Carbon
  +created_at: Carbon\Carbon    // Carbon
```

```
CodebarAg\Zammad\DTO\Ticket {
  +id: 32                                  // int
  +number: 69032                           // int
  +customer_id: 20                         // int
  +group_id: 3                             // int
  +state_id: 1                             // int
  +subject: "Login is not working"         // string
  +comments_count: 3                       // int
  +updated_at: Carbon\Carbon               // Carbon
  +created_at: Carbon\Carbon               // Carbon
  +comments: Illuminate\Support\Collection // Collection|Comment[]
}
```

```
CodebarAg\Zammad\DTO\Comment {
  +id: 66                                       // int
  +type_id: 10                                  // int
  +ticket_id: 32                                // int
  +sender_id: 2                                 // int
  +sender: "Customer"                           // string
  +subject: "App Subject"                       // string
  +body: "We have fixed your issue! Have a great dayIt is not working"
  +body_without_blockquote: "We have fixed your issue! Have a great day"
  +body_only_blockquote: "It is not working"
  +content_type: "text/plain"                   // string
  +from: "Max Mustermann"                        // string
  +to: null                                     // ?string
  +internal: false                              // boolean
  +created_by_id: 20                            // int
  +updated_by_id: 20                            // int
  +origin_by_id: 4                              // ?int
  +attachments: Illuminate\Support\Collection   // Collection|Attachment[]
  +updated_at: Carbon\Carbon                    // Carbon
  +created_at: Carbon\Carbon                    // Carbon
}
```

```
CodebarAg\Zammad\DTO\Attachment {
  +id: 313              // int
  +size: 30             // int
  +name: "log.txt"      // string
  +type: "text/plain"   // string
}
```

```
CodebarAg\Zammad\DTO\ObjectAttribute {
  +id: 313                      // int
  +name: "sample_object"        // string
  +object_lookup_id: 2          // int
  +display: "Sample Object"     // string
  +data_type: "select"          // string
  +position: 1500               // int
  +data_option: []              // array
  +data_option_new: []          // ?array
}
```

🔧 Configuration file
--------------------

[](#-configuration-file)

You can publish the config file with:

```
php artisan vendor:publish --tag="zammad-config"
```

This is the contents of the published config file:

```
