RetailCRM API Client

Users extends AbstractApiResourceGroup

Class Users

Tags
category

Users

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

get()  : UsersGetResponse
Makes GET "/api/v5/users/{id}" request.
list()  : UsersResponse
Makes GET "/api/v5/users" request.
status()  : SuccessResponse
Makes POST "/api/v5/users/{id}/status" request.
userGroups()  : UserGroupsResponse
Makes GET "/api/v5/user-groups" request.

Methods

get()

Makes GET "/api/v5/users/{id}" request.

public get(int $id) : UsersGetResponse

Example:

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

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

try {
    $response = $client->users->get(1);
} 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 'User: ' . print_r($response->user, true);
Parameters
$id : int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
UsersGetResponse

list()

Makes GET "/api/v5/users" request.

public list(UsersRequest|null $request) : UsersResponse

Example:

use RetailCrm\Api\Enum\NumericBoolean;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Users\ApiUserFilter;
use RetailCrm\Api\Model\Request\Users\UsersRequest;

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

$request                  = new UsersRequest();
$request->filter          = new ApiUserFilter();
$request->filter->active  = NumericBoolean::TRUE;
$request->filter->isAdmin = NumericBoolean::TRUE;

try {
    $response = $client->users->list($request);
} 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 'Users: ' . print_r($response->users, true);
Parameters
$request : UsersRequest|null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
UsersResponse

status()

Makes POST "/api/v5/users/{id}/status" request.

public status(int $id, UsersStatusRequest $request) : SuccessResponse

Example:

use RetailCrm\Api\Enum\Users\UserStatus;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Users\UsersStatusRequest;

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

try {
    $response = $client->users->status(1, new UsersStatusRequest(UserStatus::BUSY));
} 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);
    }
}
Parameters
$id : int
$request : UsersStatusRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

userGroups()

Makes GET "/api/v5/user-groups" request.

public userGroups(UserGroupsRequest|null $request) : UserGroupsResponse

Example:

use RetailCrm\Api\Enum\PaginationLimit;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Users\UserGroupsRequest;

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

$request        = new UserGroupsRequest();
$request->page  = 1;
$request->limit = PaginationLimit::LIMIT_20;

try {
    $response = $client->users->userGroups($request);
} 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 'User groups: ' . print_r($response->groups, true);
Parameters
$request : UserGroupsRequest|null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
UserGroupsResponse

        
On this page

Search results