PHP code example of akeneo / api-php-client
1. Go to this page and download the library: Download akeneo/api-php-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/ */
akeneo / api-php-client example snippets
ntBuilder = new \Akeneo\Pim\ApiClient\AkeneoPimClientBuilder('http://localhost/');
$client = $clientBuilder->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
$client = $clientBuilder->buildAuthenticatedByToken('client_id', 'secret', 'token', 'refresh_token');
$client->getToken();
$client->getRefreshToken();
$client = $clientBuilder->buildAuthenticatedByAppToken('app_token');
$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'],
],
]);
$clientBuilder = new \Akeneo\Pim\ApiClient\AkeneoPimClientBuilder(
'http://localhost',
['headers' => ['X-HEADER-NAME' => 'content']]
);
$client = $clientBuilder->buildAuthenticatedByToken('token');
bash
$ php composer.phar