{"id":20438312,"url":"https://github.com/zammad/zammad-api-client-php","last_synced_at":"2025-04-12T18:48:51.214Z","repository":{"id":11856290,"uuid":"70740986","full_name":"zammad/zammad-api-client-php","owner":"zammad","description":"PHP API client for Zammad Helpdesk/Support system","archived":false,"fork":false,"pushed_at":"2024-11-22T12:54:37.000Z","size":103,"stargazers_count":53,"open_issues_count":7,"forks_count":22,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-11T17:11:10.482Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://zammad.org","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zammad.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.AGPL.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-12T20:58:05.000Z","updated_at":"2025-04-08T11:50:05.000Z","dependencies_parsed_at":"2024-06-04T09:34:29.752Z","dependency_job_id":"0ac4b824-af8e-4805-a96c-7a07b8815eaa","html_url":"https://github.com/zammad/zammad-api-client-php","commit_stats":{"total_commits":64,"total_committers":15,"mean_commits":4.266666666666667,"dds":0.5,"last_synced_commit":"54b21bc38ffa9d92acdd3783d52f658b837a14bf"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zammad%2Fzammad-api-client-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zammad%2Fzammad-api-client-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zammad%2Fzammad-api-client-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zammad%2Fzammad-api-client-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zammad","download_url":"https://codeload.github.com/zammad/zammad-api-client-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618215,"owners_count":21134199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T09:10:23.274Z","updated_at":"2025-04-12T18:48:51.187Z","avatar_url":"https://github.com/zammad.png","language":"PHP","readme":"# Zammad API Client for PHP\n\nThis client can be used to access the API of the open source helpdesk [Zammad](http://www.zammad.org) via PHP.\n\n## Zammad version support\nThis client supports Zammad 3.4.1 and newer.\n\n## Installation\n\n### Requirements\nThe API client needs [composer](https://getcomposer.org/). For installation have a look at its [documentation](https://getcomposer.org/download/).\nAdditionally, the API client needs PHP 7.2 or newer.\n\n### Integration into your project\nAdd the following to the \"require\" section of your project's composer.json file:\n```json\n\"zammad/zammad-api-client-php\": \"^2.0\"\n```\n\n### Installing the API client's dependencies\nFetch the API client's code and its dependencies by updating your project's dependencies with composer:\n```\n$ composer update\n```\n\nOnce installed, you have to include the generated autoload.php into your project's code:\n```php\nrequire_once dirname(__DIR__).'/vendor/autoload.php';\n```\n\n## How to use the API client\n\n### Example code\nYou can find example code within the directory `examples`.\n\n### The Client object\nYour starting point is the `Client` object:\n```php\nuse ZammadAPIClient\\Client;\n$client = new Client([\n    'url'           =\u003e 'https://myzammad.com', // URL to your Zammad installation\n    'username'      =\u003e 'myuser@myzammad.com',  // Username to use for authentication\n    'password'      =\u003e 'mypassword',           // Password to use for authentication\n    // 'timeout'       =\u003e 15,                  // Sets timeout for requests, defaults to 5 seconds, 0: no timeout\n    // 'debug'         =\u003e true,                // Enables debug output\n    // 'verify'        =\u003e true,                // Enabled SSL verification. You can also give a path to a CA bundle file. Default is true.\n]);\n```\nBesides using a combination of `username` and `password`, you can alternatively give an `http_token` or an `oauth2_token`.\n**Important:** You have to activate API access in Zammad.\n\n### Fetching a single Resource object\nTo fetch a `Resource` object by ID, e. g. a ticket with ID 34, use the `Client` object:\n```php\nuse ZammadAPIClient\\ResourceType;\n$ticket = $client-\u003eresource( ResourceType::TICKET )-\u003eget(34);\n```\n\n`$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.\n\nNote: Once you successfully called `get` on a `Resource` object, you cannot call it again, instead you have to create a new one with `resource`.\n\n### Accessing values of Resource objects\nYou can access the values of a `Resource` object via its 'value' methods.\n```php\n$ticket-\u003esetValue( 'title', 'My ticket title' );\n$title = $ticket-\u003egetValue('title');\n$all_values = $ticket-\u003egetValues();\n```\n\nPlease 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.\n\nSo, 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.\n\nAdditionally you can have a look at the REST interface documentation of Zammad:\n\n[Introduction to the REST interface](https://docs.zammad.org/en/latest/api/intro.html)\n* [Users](https://docs.zammad.org/en/latest/api/user.html)\n* [Groups](https://docs.zammad.org/en/latest/api/group.html)\n* [Organizations](https://docs.zammad.org/en/latest/api/organization.html)\n* [Tickets](https://docs.zammad.org/en/latest/api/ticket.html)\n   * [Ticket articles](https://docs.zammad.org/en/latest/api/ticket-article.html)\n   * [Ticket priorities](https://docs.zammad.org/en/latest/api/ticket-priority.html)\n   * [Ticket states](https://docs.zammad.org/en/latest/api/ticket-state.html)\n* [Tags](https://docs.zammad.org/en/latest/api/tags.html)\n\n#### Fetching a ticket's articles\nIf you already have a ticket object, you can easily fetch its articles:\n```php\n$ticket_articles = $ticket-\u003egetTicketArticles();\n```\n\n#### Fetching content of ticket article attachments\nThe content of ticket article attachments can be fetched with a call of `getAttachmentContent()` of the ticket article resource object:\n```php\n$attachment_content = $ticket_article-\u003egetAttachmentContent(23);\n```\n\nIn 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.\n\n### Updating Resource objects\nIf you fetched a `Resource` object and changed some values, you have to send your changes to Zammad. You do this with a simple call:\n```php\n$ticket-\u003esave();\n```\n\n`save()` will check it itself but if you somehow need to know if a `Resource` object has unsaved changes, you can check it with:\n```php\nif ( $ticket-\u003eisDirty() ) {...}\n```\n\nNote: Some resource types don't support updating the values of certain fields. Please refer to the API documentation (see links above).\n\n### Creating Resource objects\nTo create a new `Resource` object, use the following code (example):\n```php\nuse ZammadAPIClient\\ResourceType;\n\n$ticket = $client-\u003eresource( ResourceType::TICKET );\n$ticket-\u003esetValue( 'title', 'My new ticket' );\n// ...\n// Set additional values\n// ...\n$ticket-\u003esave(); // Will create a new ticket object in Zammad\n```\n\n### Searching Resource objects\nSome types of resources can be searched, pagination is available.\n```php\nuse ZammadAPIClient\\ResourceType;\n\n// Fulltext search\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003esearch('some text');\n\n// Field specific search\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003esearch('title:My Title');\n\n// Field specific search with more than one field\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003esearch('title:My Title AND priority_id:1');\n\n// Pagination: Page 1, 25 entries per page\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003esearch( 'some text', 1, 25 );\n```\n\nNote 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.\n\nA 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).\nTherefore, the code for searching should look like the following:\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003esearch('some text');\nif ( !is_array($tickets) ) {\n    // Error handling\n    print $tickets-\u003egetError();\n}\nelse {\n    // Do something with $tickets array\n}\n```\n\nNote: 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.\n\n\n### Fetching 'all' Resource objects\nFor some types of resources, all available objects can be fetched, pagination is available.\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n// Fetch all tickets (keep in mind the server-side limit, see 'Searching Resource objects')\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003eall();\n\n// Fetch all tickets with pagination (keep in mind the server-side limit, see 'Searching Resource objects'), page 4, 50 entries per page\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003eall( 4, 50 );\n```\nA 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).\nTherefore, the code to use `all` should look like the following:\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n$tickets = $client-\u003eresource( ResourceType::TICKET )-\u003eall( 4, 50 ); // pagination\nif ( !is_array($tickets) ) {\n    // Error handling\n    print $tickets-\u003egetError();\n}\nelse {\n    // Do something with $tickets array\n}\n```\n\nNote: 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.\n\n### Deleting a Resource object\nTo be able to delete a `Resource` object that exists in Zammad, you must first fetch it from Zammad, either via `get`, `all` or `search`.\nYou 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.\nTo delete a `Resource` object, simply call `delete` on it:\n```php\n$ticket-\u003edelete();\n```\n\nThis 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.\n\n### Working with tags\n\n#### Adding a tag to an object\n\nZammad can assign tags to an object. Currently this is only supported for ticket objects.\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n// The third parameter 'Ticket' is the object type for which the ID will be given as first parameter.\n$client-\u003eresource( ResourceType::TAG )-\u003eadd( $ticket_id, 'tag 1', 'Ticket' );\n```\n\n\n#### Remove a tag from an object\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n$client-\u003eresource( ResourceType::TAG )-\u003eremove( $ticket_id, 'tag 1', 'Ticket' );\n```\n\n#### Getting all tags assigned to an object\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n// The second parameter 'Ticket' is the object type for which the ID will be given as first parameter.\n$tag = $client-\u003eresource( ResourceType::TAG )-\u003eget( $ticket_id, 'Ticket' );\n\n// [ 'tag 1', 'tag 2' ]\n$tags = $tag-\u003egetValue('tags')\n```\n\n#### Search for Tags\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n$tags = $client-\u003eresource( ResourceType::TAG )-\u003esearch('my tag');\n```\n### Object import\n\nBesides the usual methods available for objects, there is also a method available to import these via CSV. Example for text module CSV import:\n\n```php\nuse ZammadAPIClient\\ResourceType;\n\n$text_modules_csv_string = file_get_contents('text_modules.csv');\n\n$client-\u003eresource( ResourceType::TEXT_MODULE )-\u003eimport($text_modules_csv_string);\n\n```\n\nSee __Available resource types and their access methods__ below for resource types that support CSV import.\n\n### Handling Zammad errors\nWhen 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:\n```php\nif ( $ticket-\u003ehasError() ) {\n    print $ticket-\u003egetError();\n}\n```\n\nIf 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.\n```php\n$last_response = $client-\u003egetLastResponse();\n```\nWith this object, you can e. g. get the HTTP status code and the body of the last response.\n\n### Executing an API call on behalf of another user\nIf 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):\n```php\n$client-\u003esetOnBehalfOfUser('myuser');\n```\nAny API call after above code will use this setting. If you want to return to using the user you used for authentication, call:\n```php\n$client-\u003eunsetOnBehalfOfUser();\n```\n\nUsing this setting will be ignored by Zammad before version 2.4.\n\n## Available resource types and their access methods\n\nTo be able to use the 'short form' for the resource type, add a\n```php\nuse ZammadAPIClient\\ResourceType;\n```\n\nto your code. You then can reference the resource type like\n```php\n$client-\u003eresource( ResourceType::TICKET );\n```\n\n|Resource type|get|all|search|save|delete|add|remove|import|\n|-------------|:-:|:-:|:----:|:--:|:----:|:-:|:----:|:----:|\n| TICKET|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026ndash;|\n| TICKET_ARTICLE|\u0026#10004;|\u0026ndash;|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026ndash;|\n| TICKET_STATE|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026ndash;|\n| TICKET_PRIORITY|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026ndash;|\n| TEXT_MODULE|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026#10004;|\n| ORGANIZATION|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026#10004;|\n| GROUP|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026ndash;|\n| USER|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026#10004;|\n| TAG|\u0026#10004;|\u0026ndash;|\u0026#10004;|\u0026ndash;|\u0026ndash;|\u0026#10004;|\u0026#10004;|\u0026ndash;|\n\n## Publishing\n\n1. Add release to [CHANGELOG.md](CHANGELOG.md)\n2. Commit, tag and push.\n3. 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.\n\n## Contributing\n\nBug 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.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzammad%2Fzammad-api-client-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzammad%2Fzammad-api-client-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzammad%2Fzammad-api-client-php/lists"}