Download the PHP package bluerocktel/atera-api-php-client without Composer
On this page you can find all versions of the php package bluerocktel/atera-api-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bluerocktel/atera-api-php-client
More information about bluerocktel/atera-api-php-client
Files in bluerocktel/atera-api-php-client
Package atera-api-php-client
Short Description A light PHP client for the Atera CRM API
License MIT
Informations about the package atera-api-php-client
php-sdk
This package is a light PHP Client / SDK for the Atera API.
- Installation
- Authentication
- Usage
- Requests
- Resources
- Responses
- Entities
- Pagination
- Extending the SDK
Installation
This library requires PHP >=8.1.
You can install the package via composer:
Authentication
The autentication with the Atera API is made using an Api token you can retreive from the Atera admin panel. Read more in the Atera documentation.
After instancianting the AteraConnector class, you can start querying 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 AteraConnector 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 (Customer, Agent, Contact...).
Resources classes usually provide (but are not limited to) the following methods :
👉 The
upsert()method is a simple alias : it will call theupdate()method if the given entity has an id, or thestore()method otherwise.
Each of those namespace resources can be accessed using the AteraConnector instance :
If needed, it is also possible to create the desired resource instance manually.
Responses
Weither you are using Requests or Resources, the 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 SDK 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 SDK 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.
The create/update/upsert routes will often ask for a DTO as first parameter :
Pagination
On some index/search routes, the Atera API will use a pagination.
If you need to iterate on all pages of the endpoint, you may find handy to use the connector's paginate() method :
Read more about lazy paginations on the Saloon documentation.
Extending the SDK
You may easily extend the SDK by creating your own Resources, Requests, and Entities.
Then, by extending the AteraConnector class, add you new resources to the connector :
All versions of atera-api-php-client with dependencies
nesbot/carbon Version ^3.8.4
illuminate/collections Version >=12.0
saloonphp/saloon Version ^4.0
saloonphp/rate-limit-plugin Version ^2.0
saloonphp/pagination-plugin Version ^2.0