PHP code example of akeneo / api-php-client-ee

1. Go to this page and download the library: Download akeneo/api-php-client-ee 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/ */

    

akeneo / api-php-client-ee example snippets




ntBuilder = new \Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientBuilder('http://localhost/');
$client = $clientBuilder->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');

$client = $clientBuilder->buildAuthenticatedByToken('client_id', 'secret', 'token', 'refresh_token');

$client->getToken();
$client->getRefreshToken();

$product = $client->getProductApi()->get('top');
echo $product['identifier']; // display "top"

$searchBuilder = new \Akeneo\Pim\ApiClient\Search\SearchBuilder();
$searchBuilder->addFilter('enabled', '=', true);
$searchFilters = $searchBuilder->getFilters();

$firstPage = $client->getProductApi()->listPerPage(50, true, ['search' => $searchFilters]);

echo $firstPage->getCount();

foreach ($firstPage->getItems() as $product) {
    // do your stuff here
    echo $product['identifier'];
}

$nextPage = $firstPage->getNextPage();

$firstPage = $nextPage->getPreviousPage();

$searchBuilder = new \Akeneo\Pim\ApiClient\Search\SearchBuilder();
$searchBuilder->addFilter('enabled', '=', true);
$searchFilters = $searchBuilder->getFilters();

$products = $client->getProductApi()->all(50, ['search' => $searchFilters]);
foreach ($products as $product) {
    // do your stuff here
    echo $product['identifier'];
}

$client->getProductApi()->create('top', ['enabled' => true]);

$client->getProductApi()->upsert('top', ['family' => 'tshirt']);

$client->getProductApi()->upsertList([
    [
        'identifier' => 'top',
        'family' => 'tshirt',
    ],
    [
        'identifier' => 'cap',
        'categories' => ['hat'],
    ],
]);
bash
$ php composer.phar 

cp docker-compose.yml.dist docker-compose.yml
rm -rf composer.lock vendor/
docker-compose run client_72 composer install
docker-compose run client_72 bin/phpunit -c phpunit.xml.dist
docker-compose run client_72 bin/phpspec run
docker-compose run client_72 bin/php-cs-fixer fix --diff --dry-run --config=.php_cs.php -vvv