From 02075721f436015db1f595d7eec0c34d64721100 Mon Sep 17 00:00:00 2001 From: Alexandre Hocquard Date: Wed, 29 Nov 2017 09:25:48 +0100 Subject: [PATCH] Complete the readme for the EE --- README.md | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 34d5e62..d563a96 100644 --- a/README.md +++ b/README.md @@ -1 +1,134 @@ -# php-api-client-ee \ No newline at end of file +# PHP Akeneo PIM API + +A simple PHP client to use the [Akeneo PIM API](https://api.akeneo.com/) with the Enterprise Edition. + +## Requirements + +* PHP >= 5.6 +* Composer + +## Installation + +We use HTTPPlug as the HTTP client abstraction layer. +In this example, we will use [Guzzle](https://github.com/guzzle/guzzle) v6 as the HTTP client implementation. + +`api-php-client-ee` uses [Composer](http://getcomposer.org). +The first step to use `api-php-client-ee` is to download composer: + +```bash +$ curl -s http://getcomposer.org/installer | php +``` + +Then, run the following command to require the library: +```bash +$ php composer.phar require akeneo/api-php-client-ee php-http/guzzle6-adapter +``` + +If you want to use another HTTP client implementation, you can check [here](https://packagist.org/providers/php-http/client-implementation) the full list of HTTP client implementations. + +## Documentation + +Full documentation is available on the [API website](https://api.akeneo.com/php-client/introduction.html). + +## Getting started + +### Initialise the client +You first need to initialise the client with your credentials client id/secret and with your user/password. + +If you don't have any client id, let's take a look at [this page](https://api.akeneo.com/documentation/security.html#authentication) to create it. + +```php +buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin'); +``` + +You can authenticate to the client with your token/refresh token as well. +```php +$client = $clientBuilder->buildAuthenticatedByToken('client_id', 'secret', 'token', 'refresh_token'); +``` + +Getting the token and refresh token is as simple as: +```php +$client->getToken(); +$client->getRefreshToken(); +``` + +### Get a product + +```php +$product = $client->getProductApi()->get('top'); +echo $product['identifier']; // display "top" +``` + +### Get a list of products + +#### By getting pages + +```php +$searchBuilder = new \Akeneo\Pim\ApiClient\Search\SearchBuilder(); +$searchBuilder->addFilter('enabled', '=', true); +$searchFilters = $searchBuilder->getFilters(); + +$firstPage = $client->getProductApi()->listPerPage(50, true, ['search' => $searchFilters]); + +echo $page->getCount(); + +foreach ($page->getItems() as $product) { + // do your stuff here + echo $product['identifier']; +} + +$nextPage = $page->getNextPage(); + +$firstPage = $nextPage->getPreviousPage(); +``` + +#### By getting a cursor + +```php +$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']; +} +``` + +### Create a product + +```php +$client->getProductApi()->create('top', ['enabled' => true]); +``` + +### Upsert a product + +```php +$client->getProductApi()->upsert('top', ['family' => 'tshirt']); +``` + +### Upsert a list of of products + +```php +$client->getProductApi()->upsertList([ + [ + 'identifier' => 'top', + 'family' => 'tshirt', + ], + [ + 'identifier' => 'cap', + 'categories' => ['hat'], + ], +]); +``` + +## Support + +If you find a bug or want to submit an improvement, don't hesitate to raise an issue on Github. +Also, you can ask questions and discuss about the PHP client with the community in the [Slack User Group](https://akeneopim-ug.slack.com/messages/web-api/).