Customers
extends AbstractApiResourceGroup
in package
Class Customers
Tags
Table of Contents
Methods
- combine() : SuccessResponse
- Makes POST "/api/v5/customers/combine" request.
- create() : IdResponse
- Makes POST "/api/v5/customers/create" request.
- edit() : CustomersEditResponse
- Makes POST "/api/v5/customers/{externalId}/edit" request.
- fixExternalIds() : SuccessResponse
- Makes POST "/api/v5/customers/fix-external-ids" request.
- get() : CustomersGetResponse
- Makes GET "/api/v5/customers/{externalId}" request.
- history() : CustomersHistoryResponse
- Makes GET "/api/v5/customers/history" request.
- list() : CustomersResponse
- Makes GET "/api/v5/customers" request.
- notes() : CustomerNotesResponse
- Makes GET "/api/v5/customers/notes" request.
- notesCreate() : IdResponse
- Makes POST "/api/v5/customers/notes/create" request.
- notesDelete() : SuccessResponse
- Makes POST "/api/v5/customers/notes/{id}/delete" request.
- subscriptions() : SuccessResponse
- Makes POST "/api/v5/customers/{externalId}/subscriptions" request.
- upload() : CustomersUploadResponse
- Makes POST "/api/v5/customers/upload" request.
Methods
combine()
Makes POST "/api/v5/customers/combine" request.
public
combine(CustomersCombineRequest $request) : SuccessResponse
Example:
use RetailCrm\Api\Model\Entity\Customers\SerializedCustomerReference;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Request\Customers\CustomersCombineRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CustomersCombineRequest();
$request->customers = [
new SerializedCustomerReference(2),
new SerializedCustomerReference(3),
new SerializedCustomerReference(4),
];
$request->resultCustomer = new SerializedCustomerReference(1);
try {
$response = $client->customers->combine($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 'Result: ' . var_export($response->success, true);
Parameters
- $request : CustomersCombineRequest
Tags
Return values
SuccessResponsecreate()
Makes POST "/api/v5/customers/create" request.
public
create(CustomersCreateRequest $request) : IdResponse
Example:
use RetailCrm\Api\Enum\Customers\ContragentType;
use RetailCrm\Api\Enum\Customers\CustomerType;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Entity\Customers\Customer;
use RetailCrm\Api\Model\Entity\Customers\CustomerAddress;
use RetailCrm\Api\Model\Entity\Customers\CustomerContragent;
use RetailCrm\Api\Model\Entity\Customers\CustomerPhone;
use RetailCrm\Api\Model\Entity\Customers\CustomerTag;
use RetailCrm\Api\Model\Request\Customers\CustomersCreateRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$customer = new Customer();
$customer->type = CustomerType::CUSTOMER;
$customer->externalId = 'test_10';
$customer->managerId = 24;
$customer->contragent = new CustomerContragent();
$customer->contragent->contragentType = ContragentType::INDIVIDUAL;
$customer->tags = [
new CustomerTag('first'),
new CustomerTag('second'),
new CustomerTag('third'),
];
$customer->customFields = [
'galkatrue' => true
];
$customer->address = new CustomerAddress();
$customer->address->text = '(719) 395-5645 13990 W County 270 Rd Nathrop, Colorado(CO), 81236';
$customer->firstName = 'Test';
$customer->lastName = 'User';
$customer->patronymic = 'Tester';
$customer->email = 'tester@example.com';
$customer->phones = [
new CustomerPhone('(603) 292-6810')
];
$request = new CustomersCreateRequest();
$request->site = 'aliexpress';
$request->customer = $customer;
try {
$response = $client->customers->create($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 'Created customer with ID: ' . $response->id;
Parameters
- $request : CustomersCreateRequest
Tags
Return values
IdResponseedit()
Makes POST "/api/v5/customers/{externalId}/edit" request.
public
edit(int|string $identifier, CustomersEditRequest $request) : CustomersEditResponse
Example:
use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Customers\Customer;
use RetailCrm\Api\Model\Request\Customers\CustomersEditRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CustomersEditRequest();
$request->customer = new Customer();
$request->by = ByIdentifier::ID;
$request->site = 'aliexpress';
$request->customer->firstName = 'Test';
try {
$response = $client->customers->edit(4770, $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 'Edited customer: ' . $response->id;
Parameters
- $identifier : int|string
- $request : CustomersEditRequest
Tags
Return values
CustomersEditResponsefixExternalIds()
Makes POST "/api/v5/customers/fix-external-ids" request.
public
fixExternalIds(CustomersFixExternalIdsRequest $request) : SuccessResponse
Example:
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Entity\Customers\FixExternalRow;
use RetailCrm\Api\Model\Request\Customers\CustomersFixExternalIdsRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CustomersFixExternalIdsRequest();
$request->customers = [
new FixExternalRow(1, 'external_id_1'),
new FixExternalRow(2, 'external_id_2'),
new FixExternalRow(3, 'external_id_3'),
];
try {
$response = $client->customers->fixExternalIds($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;
}
Parameters
- $request : CustomersFixExternalIdsRequest
Tags
Return values
SuccessResponseget()
Makes GET "/api/v5/customers/{externalId}" request.
public
get(string|int $identifier[, BySiteRequest|null $request = null ]) : CustomersGetResponse
Example:
use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\BySiteRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
try {
$response = $client->customers->get(
4770,
new BySiteRequest(ByIdentifier::ID, 'bb_demo')
);
} 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 'Customer: ' . print_r($response->customer);
Parameters
- $identifier : string|int
- $request : BySiteRequest|null = null
Tags
Return values
CustomersGetResponsehistory()
Makes GET "/api/v5/customers/history" request.
public
history([CustomersHistoryRequest|null $request = null ]) : CustomersHistoryResponse
Example:
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Filter\Customers\CustomerHistoryFilter;
use RetailCrm\Api\Model\Request\Customers\CustomersHistoryRequest;
use RetailCrm\Api\Enum\PaginationLimit;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CustomersHistoryRequest();
$request->limit = PaginationLimit::LIMIT_20;
$request->page = 1;
$request->filter = new CustomerHistoryFilter();
$request->filter->sinceId = 2691;
try {
$response = $client->customers->history($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 'History: ' . print_r($response->history, true);
Parameters
- $request : CustomersHistoryRequest|null = null
Tags
Return values
CustomersHistoryResponselist()
Makes GET "/api/v5/customers" request.
public
list([CustomersRequest|null $request = null ]) : CustomersResponse
Example:
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Filter\Customers\CustomerFilter;
use RetailCrm\Api\Model\Request\Customers\CustomersRequest;
use RetailCrm\Api\Enum\NumericBoolean;
use RetailCrm\Api\Enum\PaginationLimit;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CustomersRequest();
$request->limit = PaginationLimit::LIMIT_20;
$request->page = 1;
$request->filter = new CustomerFilter();
$request->filter->sites = ['moysklad', 'aliexpress'];
$request->filter->name = '89229112322';
$request->filter->isContact = NumericBoolean::TRUE;
try {
$response = $client->customers->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 'Received customers: ' . print_r($response->customers, true);
Parameters
- $request : CustomersRequest|null = null
Tags
Return values
CustomersResponsenotes()
Makes GET "/api/v5/customers/notes" request.
public
notes([CustomersNotesRequest|null $request = null ]) : CustomerNotesResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Customers\CustomerNoteFilter;
use RetailCrm\Api\Model\Request\Customers\CustomersNotesRequest;
use RetailCrm\Api\Enum\PaginationLimit;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CustomersNotesRequest();
$request->limit = PaginationLimit::LIMIT_20;
$request->page = 1;
$request->filter = new CustomerNoteFilter();
$request->filter->customerExternalIds = ['10'];
$request->filter->createdAtFrom = '2019-08-06 12:00:00';
$request->filter->text = 'note';
try {
$response = $client->customers->notes($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 'Notes: ' . print_r($response->notes, true);
Parameters
- $request : CustomersNotesRequest|null = null
Tags
Return values
CustomerNotesResponsenotesCreate()
Makes POST "/api/v5/customers/notes/create" request.
public
notesCreate(CustomersNotesCreateRequest $request) : IdResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Customers\Customer;
use RetailCrm\Api\Model\Entity\Customers\CustomerNote;
use RetailCrm\Api\Model\Request\Customers\CustomersNotesCreateRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CustomersNotesCreateRequest();
$request->site = 'moysklad';
$request->note = new CustomerNote();
$request->note->customer = new Customer();
$request->note->customer->externalId = '10';
$request->note->managerId = 21;
$request->note->text = 'Text';
try {
$response = $client->customers->notesCreate($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 'Created note with id: ' . $response->id;
Parameters
- $request : CustomersNotesCreateRequest
Tags
Return values
IdResponsenotesDelete()
Makes POST "/api/v5/customers/notes/{id}/delete" request.
public
notesDelete(int $id) : SuccessResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
try {
$response = $client->customers->notesDelete(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;
}
Parameters
- $id : int
Tags
Return values
SuccessResponsesubscriptions()
Makes POST "/api/v5/customers/{externalId}/subscriptions" request.
public
subscriptions(int|string $identifier, CustomersSubscriptionsRequest $request) : SuccessResponse
Example:
use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Customers\Subscription;
use RetailCrm\Api\Model\Request\Customers\CustomersSubscriptionsRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$subscription = new Subscription();
$subscription->channel = 'waba';
$subscription->subscription = 'category';
$subscription->active = false;
$subscription->messageId = 123;
$request = new CustomersSubscriptionsRequest();
$request->by = ByIdentifier::ID;
$request->site = 'aliexpress';
$request->subscriptions = [$subscription];
try {
$response = $client->customers->subscriptions(4770, $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;
}
Parameters
- $identifier : int|string
- $request : CustomersSubscriptionsRequest
Tags
Return values
SuccessResponseupload()
Makes POST "/api/v5/customers/upload" request.
public
upload(CustomersUploadRequest $request) : CustomersUploadResponse
Example:
use RetailCrm\Api\Enum\Customers\ContragentType;
use RetailCrm\Api\Enum\Customers\CustomerType;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Customers\Customer;
use RetailCrm\Api\Model\Entity\Customers\CustomerAddress;
use RetailCrm\Api\Model\Entity\Customers\CustomerContragent;
use RetailCrm\Api\Model\Entity\Customers\CustomerPhone;
use RetailCrm\Api\Model\Entity\Customers\CustomerTag;
use RetailCrm\Api\Model\Entity\Customers\FixExternalRow;
use RetailCrm\Api\Model\Request\Customers\CustomersUploadRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$customer = new Customer();
$customer->type = CustomerType::CUSTOMER;
$customer->externalId = 'test_10';
$customer->managerId = 24;
$customer->contragent = new CustomerContragent();
$customer->contragent->contragentType = ContragentType::INDIVIDUAL;
$customer->tags = [
new CustomerTag('first'),
new CustomerTag('second'),
new CustomerTag('third'),
];
$customer->customFields = [
'galkatrue' => true
];
$customer->address = new CustomerAddress();
$customer->address->text = '(719) 395-5645 13990 W County 270 Rd Nathrop, Colorado(CO), 81236';
$customer->firstName = 'Test';
$customer->lastName = 'User';
$customer->patronymic = 'Tester';
$customer->email = 'tester@example.com';
$customer->phones = [
new CustomerPhone('(603) 292-6810')
];
$request = new CustomersUploadRequest();
$request->site = 'aliexpress';
$request->customers = [$customer];
try {
$response = $client->customers->upload($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 'Uploaded customers: ' . implode(', ', array_map(static function (FixExternalRow $row) {
return $row->id;
}, $response->uploadedCustomers));
Parameters
- $request : CustomersUploadRequest