Akeneo Data Loader helps you to load data to your Akeneo PIM via its REST API.
- Load YAML fixtures for testing, local development or for performance benchmarking.
- Import product data from external systems (legacy PIM or regular data providers).
- Support for bulk data upload (upsert mode).
- Simplified import of media files.
use Aa\AkeneoDataLoader\Api;
use Aa\AkeneoDataLoader\LoaderFactory;
$factory = new LoaderFactory();
$apiCredentials = Api\Credentials::create('https://your.akeneo.host/', 'clientId', 'secret', 'username', 'password');
$loader = $factory->createByCredentials($apiCredentials);
$loader->load('product', [
[
'identifier' => 'test-product',
'enabled' => true,
'family' => 'accessories',
'categories' => [
'master_accessories',
'print_accessories',
'suppliers',
],
'values' => [
'ean' => [[ 'locale' => null, 'scope' => null, 'data' => '1234567890183' ]],
'name' => [[ 'locale' => null, 'scope' => null, 'data' => 'Test product' ]],
'image' => [[ 'locale' => null, 'scope' => null, 'data' => '@file:asset/1111111171.jpg' ]],
'weight' => [[ 'locale' => null, 'scope' => null, 'data' => [ 'amount' => '500.0000', 'unit' => 'GRAM' ] ]],
],
],
]);
- Check how to load media files if you wonder what does
@file:
mean.
use Aa\AkeneoDataLoader\Api;
use Aa\AkeneoDataLoader\LoaderFactory;
use Symfony\Component\Yaml\Yaml;
$factory = new LoaderFactory();
$apiCredentials = Api\Credentials::create('https://your.akeneo.host/', 'clientId', 'secret', 'username', 'password');
$loader = $factory->createByCredentials($apiCredentials);
$productData = Yaml::parse(file_get_contents('data/product.yaml'));
$loader->load('product', $productData);
As you can see, to load data you need to know:
- Your Akeneo host and API credentials
- Data type
- Data format
I hope you know your Akeneo host, so use it by creating a Credentials
object.
Besides this, you need to know the name and password of the user that you going to use for connecting via API.
Last, but not the least, you need the client ID and secret of an API connection.
You can create a connection in you Akeneo in the System > API connection
section or
use the console command to generate it:
bin/console pim:oauth-server:create-client Import
Data loader supports the following data types:
- channel
- category
- attribute-group
- attribute
- attribute-option
- family
- family-variant
- product-model
- product
and also these Enterprise Edition data types:
- asset
- asset-variation-file
- asset-reference-file
- reference-entity
- reference-entity-record
The data format is a format of Akeneo REST API.
Check also Examples of YAML files that represent the data format.
You can simply upload a file and assign it as a value of image or file attributes.
$loader->load('product', [
'values' => [
'image' => [
[
'locale' => 'en_US',
'scope' => 'ecommerce',
'data' => '@file:relative/path/to/your/asset.jpg'
],
],
],
]);
The prefix @file:
tells Akeneo Data Loader to read this media file relative/path/to/your/asset.jpg
and assign it as the value of the attribute image
.
You can specify the base directory path for media files using configuration of LoaderFactory:
use Aa\AkeneoDataLoader\LoaderFactory;
use Aa\AkeneoDataLoader\Connector\Configuration;
$configuration = Configurationcreate('assets/baseDir/path');
$factory = new LoaderFactory($configuration);
You can use Data loader to modify data fetched using Akeneo API.
use Aa\AkeneoDataLoader\Api;
use Aa\AkeneoDataLoader\LoaderFactory;
use Akeneo\Pim\ApiClient\AkeneoPimClientBuilder;
use Akeneo\Pim\ApiClient\Search\SearchBuilder;
// Fetch data using Akeneo UPI
$clientBuilder = new AkeneoPimClientBuilder('https://your.akeneo.host/');
$client = $clientBuilder->buildAuthenticatedByPassword('clientId', 'secret', 'admin', 'admin');
$searchBuilder = new SearchBuilder();
$searchBuilder->addFilter('price', 'EMPTY');
$searchFilters = $searchBuilder->getFilters();
$products = $client->getProductApi()->all(100, ['search' => $searchFilters]);
// Send modified data back
$factory = new LoaderFactory();
$apiCredentials = Api\Credentials::create(
'https://your.akeneo.host/',
'clientId', 'secret', 'admin', 'admin');
$loader = $factory->createByCredentials($apiCredentials);
foreach ($products as $product) {
$product['enabled'] = false;
$loader->load('product', [$product]);
}