Methods
This document details the methods of the PHP client library.
Initializing the client
Begin by initializing an instance of Deskpro\API\DeskproClient, with the URL to your Deskpro instance.
<?php
use Deskpro\API\DeskproClient;
$client = new DeskproClient('http://deskpro.company.com');Guzzle is used to make HTTP requests. A default Guzzle client will be used by the library, but a custom instance may be provided.
<?php
use Deskpro\API\DeskproClient;
use GuzzleHttp\Client;
$httpClient = new Client([
'timeout' => 60
]);
$client = new DeskproClient('http://deskpro.company.com', $httpClient);
// Or use the setter method.
// $client->setHTTPClient($httpClient);An instance of Psr\Log\LoggerInterface may also be passed to the constructor when initializing the client.
Authenticating
Many API methods require authentication. Set the ID of the user to authenticate with and either the auth "key" or "token".
Get
Sends a GET request to the API.
DeskproClientInterface::get($endpoint, array $params = []) : APIResponseInterface
Post
Sends a POST request to the API.
DeskproClientInterface::post($endpoint, $body = null, array $params = []) : APIResponseInterface
Put
Sends a PUT request to the API.
DeskproClientInterface::put($endpoint, $body = null, array $params = []) : APIResponseInterface
Delete
Sends a DELETE request to the API.
DeskproClientInterface::delete($endpoint, array $params = []) : APIResponseInterface
Batch
Sends a batch request to the API.
DeskproClientInterface::batch(array $requests) : APIResponseInterface[]
Request
Sends a custom request to the API.
DeskproClientInterface::request($method, $endpoint, $body = null, array $params = [], array $headers = []) : APIResponseInterface
Asynchronous Requests
Each of the methods get, post, put, delete, batch, and request have asynchronous versions which return a promise.
Default Headers
Sets the headers sent with each request.
Response
Each of the methods get, post, put, delete, batch, and request returns an instance of APIResponseInterface.
APIResponseInterface::getData() : array
APIResponseInterface::getMeta() : array
APIResponseInterface::getLinked() : array
For asynchronous requests, an instance of APIResponseInterface is passed to the resolver function.
The APIResponseInterface interface implements ArrayAccess, Iterator, and Countable.
Last updated