PHP client and examples

February 28, 2024


Library / SDK

An adapter class for making Erply API calls is available from Github:

https://github.com/erply/api-client

Sample usage

require __DIR__ . '/library/ApiClient.php'; // Adjust the path as necessary

$client = new \Erply\ApiClient\ApiClient();

$client
    ->setUrl('https://123.erply.com/api')
    ->setClientCode('123')
    ->setUsername('myuser')
    ->setPassword('mypassword')
    ->setConnectionTimeout(60)
    ->setExecutionTimeout(60);

print_r($client->sendRequest('getCustomerGroups'));

The sendRequest function returns API's response as an array structure. The above sample outputs:

/**
 * Prints:
 * Array
 * (
 *   [status] => Array
 *   (
 *     [request] => getReasonCodes
 *     [requestUnixTime] => 1709111082
 *     [responseStatus] => ok
 *     [errorCode] => 0
 *     [generationTime] => 0.08368992805481
 *     [recordsTotal] => 5
 *     [recordsInResponse] => 5
 *   )
 *   [records] => Array
 *   (
 *     [0] => Array
 *     (
 *       [reasonID] => 1
 *       [name] => samples
 *       [added] => 0
 *       [lastModified] =>
 *       [purpose] =>
 *       [code] =>
 *       [manualDiscountDisablesPromotionTiers] => Array
 *       (
 *       )
 *     )
 *     ...
 */