PHP API Client documentation

#Getting started

#Requirements

  • PHP >= 5.6
  • Composer

#Compatibility matrix

Below you will find which PHP client version to use depending on your PIM version.

PIM version REST API PHP client version End of life
v2.0 v1.0 March 2019
v2.1 - v2.2 v2.0 March 2019
v2.3 v3.0 December 2019
v3.0 - v3.1 v4.0 August 2020
v3.2 - v4.0 v5.0 August 2021
v5.0 - SaaS v6.0 August 2022

Note that our PHP client is backward compatible.

For example, if your PIM is currently a v2.3, you can still use a 1.0 version of the PHP client. The new endpoints available in v2.3 will not be available in the v1.0 of the PHP client.

#Installation

api-php-client and api-php-client-ee use Composer. The first step is to download Composer:

$ curl -s http://getcomposer.org/installer | php
    

We use HTTPPlug as the HTTP client abstraction layer. If you want to know more about this, it's documented here. In this example, we will use Guzzle v6 as the HTTP client implementation.

Run the following command to require the libraries in your project:

#Community Edition

$ php composer.phar require akeneo/api-php-client php-http/guzzle6-adapter:^2.0 http-interop/http-factory-guzzle:^1.0
    

#Enterprise Edition

$ php composer.phar require akeneo/api-php-client-ee php-http/guzzle6-adapter:^2.0 http-interop/http-factory-guzzle:^1.0
    

If you don't know which implementation to choose, we strongly recommend you to use Guzzle v6, as in the previous example.

#Initialization of the client

You first need to initialize the client with your credentials (client id, secret, username and password).

If you don't have any client id/secret, let's take a look at this page to create it.

#Community Edition

<?php
    
    require_once __DIR__ . '/vendor/autoload.php';
    
    $clientBuilder = new \Akeneo\Pim\ApiClient\AkeneoPimClientBuilder('http://localhost/');
    $client = $clientBuilder->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
    

You can authenticate to the client with your token/refresh token as well.

<?php
    
    require_once __DIR__ . '/vendor/autoload.php';
    
    $clientBuilder = new \Akeneo\Pim\ApiClient\AkeneoPimClientBuilder('http://localhost/');
    $client = $clientBuilder->buildAuthenticatedByToken('client_id', 'secret', 'token', 'refresh_token');
    

#Enterprise Edition

<?php
    
    require_once __DIR__ . '/vendor/autoload.php';
    
    $clientBuilder = new \Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientBuilder('http://localhost/');
    $client = $clientBuilder->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
    

You can authenticate to the client with your token/refresh token as well.

<?php
    
    require_once __DIR__ . '/vendor/autoload.php';
    
    $clientBuilder = new \Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientBuilder('http://localhost/');
    $client = $clientBuilder->buildAuthenticatedByToken('client_id', 'secret', 'token', 'refresh_token');
    

Want to know more about authentication? It's over there.

#Make your first call

Getting a product is as simple as:

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

Want to update an attribute, create a category or delete a product? You can get code snippets for all the resources here