A PHP library is provided to ease the development of PHP applications that connect to Ticketmatic. This library is automatically kept in sync with the backend implementation: all endpoints that can be used through the REST API will also be usable through the PHP library.
The PHP library frees you from the burden of having to implement correct authentication crypto or some of the more tricky type handling: the library takes care of all those things.
Some important features of the PHP library:
- Converts all results into typed objects
- All classes and methods are (optionally) strongly-typed and annotated with PHPDoc annotations. This allows autocompletion in editors such as PhpStorm.
- Automatically handles conversions between the Ticketmatic time format and PHP’s builtin DateTime class.
- Supports custom fields
Getting the library
The PHP library is available on Github: https://github.com/ticketmatic/tm-php.
There is also an RSS (Atom) feed available at https://github.com/ticketmatic/tm-php/releases.atom if you want to be notified on new releases.
If you are using composer, just run the following to add the Ticketmatic API library to your project:
composer require ticketmatic/phpsdk
The library comes with correct PSR-4 autoloader configuration, so simply adding it through composer should make it usable in your application.
Using composer is the recommended way of installing the PHP library.
All code lives in the
Model classes (for the strongly-typed style) can be found in
Ticketmatic\Model. These types are also used as the result for each operation.
API Endpoints can be found under
Ticketmatic\Endpoints. Sub-namespaces are used in the same way as the REST API is structured.
Creating an API client
All operations require a
1use Ticketmatic\Client; 2 3$client = new Client($accountcode, $accesskey, $secretkey);
You can find the account code and access keys on the details page of your application. See Authentication for more details on how to obtain API keys.
This client object should be passed as the first parameter to all operations. For instance, to fetch a contact you’d do the following:
1use Ticketmatic\Endpoints\Contacts; 2 3// Fetch the contact with ID 123 4$contact = Contacts::get($client, 123);
Two programming styles
The library supports two styles of passing parameters: a compact version based on arrays or a more verbose variant based on strongly-typed objects. You can freely mix styles: whichever you use is up to personal preference.
The examples below will illustrate the difference between both styles.
1Contacts::create($client, array( 2 "email" => "email@example.com", 3 "firstname" => "John", 4 "lastname" => "Doe", 5));
1use Ticketmatic\Model\Contact; 2 3$contact = new Contact(); 4$contact->email = "firstname.lastname@example.org"; 5$contact->firstname = "John"; 6$contact->lastname = "Doe"; 7 8Contacts::create($client, $contact);
The strongly-typed variant allows you to benefit from autocompletion and type hints.
Results are always returned as objects, regardless of the style used to call endpoints.
Use the selector in the sidebar to show PHP examples when browsing the API documentation.