malexstore-php-sdk
PHP library for Malex Store API interaction, includes OAuth authorization and API methods. Full API features documentation can be found here.
1. Prerequisites
- PHP 7.1 or later
2. Installation
The PHP SDK can be installed using Composer by running the following command:
composer require k-orolevsk-y/malexstore-php-sdk
3. Initialization
Create ApiClient object using the following code:
$mapi = new MalexStore\Client\ApiClient($access_token);
Also you can initialize ApiClient
with different API host:
$mapi = new MalexStore\Client\ApiClient($access_token, 'v2.malex-store.ru/api');
4. Authorization Code Flow
OAuth Authorization Code Flow allows calling methods from the server side.
Create OAuth
object first:
$oauth = new MalexStore\OAuth\OAuth();
4.1. For getting user access key use following command:
$oauth = new MalexStore\OAuth\OAuth();
$user = 1234567;
$client_id = 1234567;
$client_token = 'access_token';
$response = MalexStore\OAuth\OAuthResponseType::CODE
$code = $oauth->authorize($user, $response, $client_id, $client_token);
4.1.1. Or if you want to get community access key use:
Then use this method to get the access token:
$oauth = new MalexStore\OAuth\OAuth();
$client_id = 1234567;
$client_secret = 'SDAScasd'
$code = 'CODE';
$response = $oauth->getAccessToken($code, $client_id, $client_secret);
$access_token = $response['access_token'];
The redirect_uri should be the URL that was used to get a code at the first step.
5. API Requests
You can find the full list of API methods here.
5.1. Request sample
Example of calling method users/get:
$mapi = new MalexStore\Client\ApiClient();
$response = $mapi->users()->get($access_token, [
'ids' => [1, 210700286]
]);
5.2. Uploading Files
Please read the full manual before the start.
Then use files/upload method to send files.
$mapi = new MalexStore\Client\ApiClient();
$file = $mapi->files()->upload('photo.jpg');
The rest of the documentation is on the site.