Costs
extends AbstractApiResourceGroup
in package
Class Costs
Tags
Table of Contents
Methods
- costsDelete() : CostsDeleteResponse
- Makes POST "/api/v5/costs/delete" request.
- costsUpload() : CostsUploadResponse
- Makes POST "/api/v5/costs/upload" request.
- create() : IdResponse
- Makes POST "/api/v5/costs/create" request.
- delete() : SuccessResponse
- Makes POST "/api/v5/costs/{id}/delete" request.
- edit() : IdResponse
- Makes POST "/api/v5/costs/{id}/edit" request.
- get() : CostsGetResponse
- Makes GET "/api/v5/costs/{id}" request.
- list() : CostsResponse
- Makes GET "/api/v5/costs" request.
Methods
costsDelete()
Makes POST "/api/v5/costs/delete" request.
public
costsDelete(CostsDeleteRequest $request) : CostsDeleteResponse
Example:
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Request\Costs\CostsDeleteRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CostsDeleteRequest();
$request->ids = [2, 3, 5, 8, 13, 21];
try {
$response = $client->costs->costsDelete($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;
}
printf('Deleted %d costs.', $response->count);
Parameters
- $request : CostsDeleteRequest
Tags
Return values
CostsDeleteResponsecostsUpload()
Makes POST "/api/v5/costs/upload" request.
public
costsUpload(CostsUploadRequest $request) : CostsUploadResponse
Example:
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Entity\Costs\Cost;
use RetailCrm\Api\Model\Request\Costs\CostsUploadRequest;
use RetailCrm\Api\Model\Entity\Source;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CostsUploadRequest();
$cost = new Cost();
$cost->sites = ['aliexpress'];
$cost->source = new Source();
$cost->source->source = 'source';
$cost->source->campaign = 'campaign';
$cost->source->content = 'content';
$cost->source->keyword = 'keyword';
$cost->source->medium = 'medium';
$cost->comment = 'comment';
$cost->costItem = 'products-purchase-price';
$cost->createdAt = new DateTime();
$cost->dateFrom = new DateTime();
$cost->dateTo = new DateTime();
$cost->summ = 100.10;
$request->costs = [$cost];
try {
$response = $client->costs->costsUpload($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 costs with IDs: ' . implode(', ', $response->uploadedCosts);
Parameters
- $request : CostsUploadRequest
Tags
Return values
CostsUploadResponsecreate()
Makes POST "/api/v5/costs/create" request.
public
create(CostsCreateRequest $request) : IdResponse
Example:
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Entity\Costs\Cost;
use RetailCrm\Api\Model\Request\Costs\CostsCreateRequest;
use RetailCrm\Api\Model\Entity\Source;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CostsCreateRequest();
$request->site = 'aliexpress';
$request->cost = new Cost();
$request->cost->sites = ['aliexpress'];
$request->cost->source = new Source();
$request->cost->source->source = 'source';
$request->cost->source->campaign = 'campaign';
$request->cost->source->content = 'content';
$request->cost->source->keyword = 'keyword';
$request->cost->source->medium = 'medium';
$request->cost->comment = 'comment';
$request->cost->costItem = 'products-purchase-price';
$request->cost->createdAt = new DateTime();
$request->cost->dateFrom = new DateTime();
$request->cost->dateTo = new DateTime();
$request->cost->summ = 100.10;
try {
$response = $client->costs->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 cost with ID: ' . $response->id;
Parameters
- $request : CostsCreateRequest
Tags
Return values
IdResponsedelete()
Makes POST "/api/v5/costs/{id}/delete" request.
public
delete(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->costs->delete(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 'Status: ' . var_export($response->success, true);
Parameters
- $id : int
Tags
Return values
SuccessResponseedit()
Makes POST "/api/v5/costs/{id}/edit" request.
public
edit(int $id, CostsEditRequest $request) : IdResponse
Example:
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Entity\Costs\Cost;
use RetailCrm\Api\Model\Request\Costs\CostsEditRequest;
use RetailCrm\Api\Model\Entity\Source;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new CostsEditRequest();
$request->site = 'aliexpress';
$request->cost = new Cost();
$request->cost->sites = ['aliexpress'];
$request->cost->source = new Source();
$request->cost->source->source = 'source';
$request->cost->source->campaign = 'campaign';
$request->cost->source->content = 'content';
$request->cost->source->keyword = 'keyword';
$request->cost->source->medium = 'medium';
$request->cost->comment = 'comment';
$request->cost->costItem = 'products-purchase-price';
$request->cost->createdAt = new DateTime();
$request->cost->dateFrom = new DateTime();
$request->cost->dateTo = new DateTime();
$request->cost->summ = 100.10;
try {
$response = $client->costs->edit(1, $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 cost with ID: ' . $response->id;
Parameters
- $id : int
- $request : CostsEditRequest
Tags
Return values
IdResponseget()
Makes GET "/api/v5/costs/{id}" request.
public
get(int $id) : CostsGetResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
try {
$response = $client->costs->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 'Received cost: ' . print_r($response->cost, true);
Parameters
- $id : int
Tags
Return values
CostsGetResponselist()
Makes GET "/api/v5/costs" request.
public
list([CostsRequest|null $request = null ]) : CostsResponse
Example:
use RetailCrm\Api\Enum\PaginationLimit;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Model\Filter\Costs\CostFilter;
use RetailCrm\Api\Model\Request\Costs\CostsRequest;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$costsRequest = new CostsRequest();
$costsRequest->limit = PaginationLimit::LIMIT_20;
$costsRequest->page = 1;
$costsRequest->filter = new CostFilter();
$costsRequest->filter->sites = ['moysklad', 'aliexpress'];
$costsRequest->filter->maxSumm = 20;
try {
$response = $client->costs->list($costsRequest);
} 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 costs: ' . print_r($response->costs, true);
Parameters
- $request : CostsRequest|null = null