PHPackages                             retailcrm/api-client-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. retailcrm/api-client-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

retailcrm/api-client-php
========================

PHP client for RetailCRM API

v6.15.24(5mo ago)68981.8k↑12.7%62[1 PRs](https://github.com/retailcrm/api-client-php/pulls)1MITPHPPHP &gt;=7.3CI passing

Since Oct 15Pushed 5mo ago14 watchersCompare

[ Source](https://github.com/retailcrm/api-client-php)[ Packagist](https://packagist.org/packages/retailcrm/api-client-php)[ Docs](http://www.retailcrm.pro/)[ RSS](/packages/retailcrm-api-client-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (30)Versions (147)Used By (1)

[![Build Status](https://github.com/retailcrm/api-client-php/workflows/CI/badge.svg)](https://github.com/retailcrm/api-client-php/actions)[![Coverage](https://camo.githubusercontent.com/1b9bccf35a9b7cc1cad29347241e4f1fe67b10143c210cd29ebdafe493b53f46/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f72657461696c63726d2f6170692d636c69656e742d7068702f6d61737465722e7376673f6c6f676f3d636f6465636f76266c6f676f436f6c6f723d7768697465)](https://codecov.io/gh/retailcrm/api-client-php)[![Latest stable](https://camo.githubusercontent.com/c27ab0f25614a11d669ad77284fa2bd08f8407771c20d771e516e3a7180fd37b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72657461696c63726d2f6170692d636c69656e742d7068702e737667)](https://packagist.org/packages/retailcrm/api-client-php)[![PHP from Packagist](https://camo.githubusercontent.com/da1c9b8d7d19b5a797663d74ed1d5a8ecb987461102a06df484d2a2517f5bf47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72657461696c63726d2f6170692d636c69656e742d7068702e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/retailcrm/api-client-php)

RetailCRM API PHP client
========================

[](#retailcrm-api-php-client)

This is the PHP RetailCRM API client. This library allows using of the actual API version.
You can find more info in the [documentation](doc/index.md).

Table of contents
=================

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Notes](#notes)
- [Documentation](doc/index.md)

Requirements
------------

[](#requirements)

- PHP 7.3 and above
- PHP's cURL support
- PHP's JSON support
- Any HTTP client compatible with PSR-18 (covered by the installation instructions).
- Any HTTP factories implementation compatible with PSR-17 (covered by the installation instructions).
- Any HTTP messages implementation compatible with PSR-7 (covered by the installation instructions).
- Other dependencies listed in the `composer.json` (covered by the installation instructions)

Installation
------------

[](#installation)

Follow those steps to install the library:

1. Download and install [Composer](https://getcomposer.org/download/) package manager.
2. Install the library from the Packagist by executing this command:

```
composer require retailcrm/api-client-php:"~6.0"
```

During the installation you will see this message. Press `'y'` when you do:

```
civicrm/composer-compile-plugin contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "civicrm/composer-compile-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
```

After that, you may see a message which will look like this:

```
The following packages have new compilation tasks:
 - retailcrm/api-client-php has 1 task

Allow these packages to compile? ([y]es, [a]lways, [n]o, [l]ist, [h]elp)
```

Choose `[a]lways` by typing `a` and pressing Enter.

**Note:** You should choose `'y'` and `[a]lways` if your application is using CI/CD pipeline because the interactive terminal is not available in that environment which will result in failure during the dependencies installation.

If you chose something else during the installation and API client doesn't work properly - please follow [these instructions](doc/compilation_prompt.md#ive-chosen-something-else-now-api-client-doesnt-work) to fix the problem.

3. Include the autoloader if it's not included, or you didn't use Composer before.

```
require 'path/to/vendor/autoload.php';
```

Replace `path/to/vendor/autoload.php` with the correct path to Composer's `autoload.php`.

**Note:** API client uses `php-http/curl-client` and `nyholm/psr7` as a PSR-18, PSR-17 and PSR-7 implementation. You can replace those implementations during installation by installing this library with the implementation of your choice, like this:

```
composer require symfony/http-client guzzlehttp/psr7 retailcrm/api-client-php:"~6.0"
```

More information about that can be found in the [documentation](doc/customization/different_psr_implementations.md).

Usage
-----

[](#usage)

Firstly, you should initialize the Client. The easiest way to do this is to use the `SimpleClientFactory`:

```
$client = \RetailCrm\Api\Factory\SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
```

The client is separated into several resource groups, all of which are accessible through the Client's public properties. You can call API methods from those groups like this:

```
$client->api->credentials();
```

For example, you can retrieve the customers list:

```
$client = \RetailCrm\Api\Factory\SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$response = $client->customers->list();
```

Or the orders list:

```
$client = \RetailCrm\Api\Factory\SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$response = $client->orders->list();
```

To handle errors you must use two types of exceptions:

- `RetailCrm\Api\Interfaces\ClientExceptionInterface` for the network or other runtime errors.
- `RetailCrm\Api\Interfaces\ApiExceptionInterface` for the errors from the API.

An example of error handling can be found in the next section of this document.

Each resource group is responsible for the corresponding API section. For example, `costs` resource group provide methods for costs manipulation and `loyalty` resource group allows interacting with loyalty programs, accounts, bonuses, etc.

Use annotations to determine which DTOs you need for sending the requests. If annotations are not provided by your IDE - you probably should configure them. It'll ease your work with this (and any other) library a lot.

More information about the usage including examples can be found in the [documentation](doc/usage/usage.md).

Examples
--------

[](#examples)

Listing orders:

```
