PHP code example of magentix / unopim-php-api-client

1. Go to this page and download the library: Download magentix/unopim-php-api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

magentix / unopim-php-api-client example snippets


$apiUrl = 'https://www.example.com';
$clientId = '1a1b1c1d-2e2f-3g3h-4i4j-5k5l5m5n5o5p';
$clientSecret = '1a3b5c7d9e2f4g6h8i1j3k5l7m9n2o4p6q8r1s3t';
$username = '[email protected]';
$password = 'Password';

$cache = new \Magentix\UnoPimApiClient\UnoPimApiCache(
    __DIR__ . DIRECTORY_SEPARATOR . 'api_cache', // The cache file directory path
    86400 // Request lifetime in seconds (GET requests in HTTP 200 are cached, 0 to disable)
);

$client = new \Magentix\UnoPimApiClient\UnoPimApiClient(
    $apiUrl,
    $clientId,
    $clientSecret,
    $username,
    $password,
    $cache,
    3000 // Authentication lifetime (need to be lower that the access token TTL, 0 to disable)
);

$result = $client->get('/api/v1/rest/categories');

$params = [
    'filters' => [
        'categories' => [
            [
                'operator' => 'IN',
                'value' => ['beers']
            ]
        ]
    ],
    'limit' => 10,
];
$result = $client->get('/api/v1/rest/products', $params);

$data = [
    'code' => 'beers',
    'parent' => 'root',
    'additional_data' => [
        'locale_specific' => [
            'en_US' => ['name' => 'Beers'],
            'fr_FR' => ['name' => 'Bières'],
        ]
    ]
];
$result = $client->post('/api/v1/rest/categories', $data);

$data = [
    'parent' => 'root',
    'additional_data' => [
        'locale_specific' => [
            'en_US' => ['name' => 'Beers'],
            'fr_FR' => ['name' => 'Bières'],
        ]
    ]
];
$result = $client->put('/api/v1/rest/categories/beers', $data);