RetailCRM API Client

Tasks extends AbstractApiResourceGroup

Class Tasks

Tags
category

Tasks

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

create()  : IdResponse
Makes POST "/api/v5/tasks/create" request.
edit()  : SuccessResponse
Makes POST "/api/v5/tasks/{id}/edit" request.
get()  : TasksGetResponse
Makes GET "/api/v5/tasks/{id}" request.
getComments()  : TaskGetCommentsResponse
Makes GET "/api/v5/tasks/{id}/comments" request.
history()  : TasksHistoryResponse
Makes GET "/api/v5/tasks/history" request.
list()  : TasksResponse
Makes GET "/api/v5/tasks" request.

Methods

create()

Makes POST "/api/v5/tasks/create" request.

public create([TasksCreateRequest|null $request = null ]) : IdResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Tasks\AbstractCustomer;
use RetailCrm\Api\Model\Entity\Tasks\Task;
use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;

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

$request                    = new TasksCreateRequest();
$request->task              = new Task();
$request->task->text        = 'Test task #1';
$request->task->performerId = 27;
$request->task->customer    = new AbstractCustomer(null, 'ru1067815391', 'aliexpress');
$request->site              = 'aliexpress';

try {
    $response = $client->tasks->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 task: ' . $response->id;
Parameters
$request : TasksCreateRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
IdResponse

edit()

Makes POST "/api/v5/tasks/{id}/edit" request.

public edit(int $id, TasksCreateRequest $request) : SuccessResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Tasks\Task;
use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;

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

$request                    = new TasksCreateRequest();
$request->task              = new Task();
$request->task->text        = 'Test task #1 (edited)';
$request->site              = 'aliexpress';

try {
    $response = $client->tasks->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);
    }
}
Parameters
$id : int
$request : TasksCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

get()

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

public get(int $id) : TasksGetResponse

Example:

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

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

try {
    $response = $client->tasks->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 'Task: ' . print_r($response->task, 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
TasksGetResponse

getComments()

Makes GET "/api/v5/tasks/{id}/comments" request.

public getComments(int $id, TaskGetCommentsRequest $request) : TaskGetCommentsResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Tasks\TaskGetCommentsRequest;

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

$request        = new TaskGetCommentsRequest();
$request->limit = 100;
$request->page  = 1;

try {
    $response = $client->tasks->getComments(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 'Task: ' . print_r($response->task, true);
Parameters
$id : int
$request : TaskGetCommentsRequest
Tags
throws
ApiException
throws
ClientException
throws
HandlerException
throws
ApiExceptionInterface
Return values
TaskGetCommentsResponse

history()

Makes GET "/api/v5/tasks/history" request.

public history([TaskHistoryRequest|null $request = null ]) : TasksHistoryResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter;
use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;

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

$request                  = new TaskHistoryRequest();
$request->limit           = 100;
$request->page            = 1;
$request->filter          = new TaskHistoryFilter();
$request->filter->sinceId = 1;

try {
    $response = $client->tasks->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 'Tasks history: ' . print_r($response->history, true);
Parameters
$request : TaskHistoryRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
TasksHistoryResponse

list()

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

public list([TasksRequest|null $request = null ]) : TasksResponse

Example:

use RetailCrm\Api\Enum\Tasks\TaskStatus;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Tasks\TaskFilter;
use RetailCrm\Api\Model\Request\Tasks\TasksRequest;

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

$request                     = new TasksRequest();
$request->filter             = new TaskFilter();
$request->filter->performers = [27];
$request->filter->status     = TaskStatus::COMPLETED;

try {
    $response = $client->tasks->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 'Tasks: ' . print_r($response->tasks, true);
Parameters
$request : TasksRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
TasksResponse

        
On this page

Search results