RetailCRM API Client

Api extends AbstractApiResourceGroup
in package

Class Api

Tags
category

Api

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

__construct()  : mixed
Api constructor.
apiVersions()  : ApiVersionsResponse
Makes GET "/api/api-versions" request.
credentials()  : Credentials
Makes GET "/api/credentials" request.
systemInfo()  : SystemInfoResponse
Makes GET "/api/system-info" request.

Methods

__construct()

Api constructor.

public __construct(string $baseUrl, ClientInterface $httpClient, RequestTransformerInterface $requestTransformer, ResponseTransformerInterface $responseTransformer, EventDispatcherInterface|null $eventDispatcher[, LoggerInterface|null $logger = null ]) : mixed
Parameters
$baseUrl : string
$httpClient : ClientInterface
$requestTransformer : RequestTransformerInterface
$responseTransformer : ResponseTransformerInterface
$eventDispatcher : EventDispatcherInterface|null
$logger : LoggerInterface|null = null

apiVersions()

Makes GET "/api/api-versions" request.

public apiVersions() : ApiVersionsResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

try {
    $apiVersions = $client->api->apiVersions();
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Available API versions: ' . implode(', ', $apiVersions->versions);
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
ApiVersionsResponse

credentials()

Makes GET "/api/credentials" request.

public credentials() : Credentials

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

try {
    $credentials = $client->api->credentials();
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Available methods ' . implode(', ', $credentials->credentials);
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
Credentials

systemInfo()

Makes GET "/api/system-info" request.

public systemInfo() : SystemInfoResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

try {
    $systemInfo = $client->api->systemInfo();
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Technical URL: ' . $systemInfo->technicalUrl;
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SystemInfoResponse

        
On this page

Search results