Download the PHP package bluerocktel/glpi-php-api-client without Composer
On this page you can find all versions of the php package bluerocktel/glpi-php-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bluerocktel/glpi-php-api-client
More information about bluerocktel/glpi-php-api-client
Files in bluerocktel/glpi-php-api-client
Package glpi-php-api-client
Short Description PHP Client for the GLPI API
License MIT
Informations about the package glpi-php-api-client
php-sdk
This package is a light PHP Wrapper / SDK for the GLPI Project API.
- Installation
- Authentication
- Usage
- Requests
- Resources
- Responses
- Entities
- Extending the Client
Installation
This library requires PHP >=8.1
.
You can install the package via composer:
Authentication
User token
To get started, first generate an App token and a User token from your GLPI dashboard. Then, you can initiate the GlpiConnector
class providing your instance URL, App token and User token :
If the connector fails to retreive a Session token from the provided credentials, a
BlueRockTEL\Glpi\Exceptions\AuthenticationException
will be thrown.
You can now start using the API :
Usage
To query the API, you can either call each API Endpoints requests individually, or make use of provided Resources classes which groups the requests into clusters.
Using Requests
Using single requests is pretty straightforward. You can use the call()
method of the GlpiConnector
class to send the desired request to the instance :
Using Resources
Using resources is a more convenient way to query the API. Each Resource class groups requests by specific API namespaces (User, Ticket, Profile...).
Each of those namespace resources can be accessed using the GlpiConnector
instance :
If needed, it is also possible to create the desired resource instance manually.
Responses
After issuing a request, the returned response is always an instance of Saloon\Http\Response
class.
It provides some useful methods to check the response status and get the response data.
You can learn more about responses by reading the Saloon documentation, which this client uses underneath.
Entities (DTO)
When working with APIs, dealing with a raw or JSON response can be tedious and unpredictable.
To make it easier, this Api client provides a way to transform the response data into a Data Transfer Object (DTO, later called Entities). This way, you are aware of the structure of the data you are working with, and you can access the data using object typed properties instead of untyped array keys.
Although you can use the dto()
method to transform the response data into an entity, it is recommended to use the dtoOrFail()
method instead. This method will throw an exception if the response status is not 2xx, instead of returning an empty DTO.
It is still possible to access the underlying response object using the getResponse()
method of the DTO :
Learn more about working with Data tranfert objects on the Saloon documentation.
Extending the Client
You may easily extend the Client by creating your own Resources, Requests, and Entities.
Then, by extending the GlpiConnector
class, add your new resources to the connector :
All versions of glpi-php-api-client with dependencies
nesbot/carbon Version ^2.68|^3.0
illuminate/collections Version >=9.0
saloonphp/saloon Version ^3.0
saloonphp/rate-limit-plugin Version ^2.0
saloonphp/pagination-plugin Version ^2.0