RetailCRM API Client

Files extends AbstractApiResourceGroup

Class Files

Tags
category

Files

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

delete()  : SuccessResponse
Makes POST "/api/v5/files/{id}/delete" request.
download()  : FilesDownloadResponse
Makes GET "/api/v5/files/{id}/download" request.
edit()  : FilesUploadResponse
Makes POST "/api/v5/files/{id}/edit" request.
get()  : FilesGetResponse
Makes GET "/api/v5/files/{id}" request.
list()  : FilesResponse
Makes GET "/api/v5/files" request.
upload()  : FilesUploadResponse
Makes POST "/api/v5/files/upload" request.

Methods

delete()

Makes POST "/api/v5/files/{id}/delete" request.

public delete(int $fileId) : SuccessResponse

Example:

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

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

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

download()

Makes GET "/api/v5/files/{id}/download" request.

public download(int $fileId) : FilesDownloadResponse

Example:

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

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

try {
    $response = $client->files->download(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;
}

printf('Saving downloaded file to "%s."', $response->fileName);
file_put_contents($response->fileName, $response->data->getContents());
Parameters
$fileId : int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
FilesDownloadResponse

edit()

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

public edit(int $fileId, FilesEditRequest $request) : FilesUploadResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Files\File;
use RetailCrm\Api\Model\Request\Files\FilesEditRequest;

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

$request                 = new FilesEditRequest();
$request->file           = new File();
$request->file->filename = 'Test File.xml';

try {
    $response = $client->files->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 file: ' . $response->file->id;
Parameters
$fileId : int
$request : FilesEditRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
FilesUploadResponse

get()

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

public get(int $fileId) : FilesGetResponse

Example:

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

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

try {
    $response = $client->files->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 'Got file: ' . print_r($response->file, true);
Parameters
$fileId : int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
FilesGetResponse

list()

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

public list([FilesRequest|null $request = null ]) : FilesResponse

Example:

use RetailCrm\Api\Enum\PaginationLimit;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Files\FileFilter;
use RetailCrm\Api\Model\Request\Files\FilesRequest;

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

$request                 = new FilesRequest();
$request->filter         = new FileFilter();
$request->filter->sites  = ['moysklad', 'aliexpress'];
$request->filter->sizeTo = 20;
$request->page           = 1;
$request->limit          = PaginationLimit::LIMIT_20;

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

upload()

Makes POST "/api/v5/files/upload" request.

public upload(FilesUploadRequest $request) : FilesUploadResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Files\FilesUploadRequest;

$client   = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$fileData = $client->getStreamFactory()->createStreamFromFile('report.xlsx');

try {
    $response = $client->files->upload(new FilesUploadRequest($fileData));
} 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 file: ' . print_r($response->file->id, true);
Parameters
$request : FilesUploadRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
FilesUploadResponse

        
On this page

Search results