#How to retrieve PIM structure

Retrieve the PIM structure through a channel resource. This is usually the required step before starting to read the PIM catalog data.

Use case:
App Workflow
PIM Features:
Channel
REST API endpoint(s):
channel
If you're starting building your App, make sure you previously followed:

#Context

The channel resource holds the basic PIM structure data.

relationship schema

Get the big picture here.

#Fetch the PIM structure

#0. Initialization


    $pimUrl = 'https://url-of-your-pim.com';
    $appToken = 'your_app_token'; // Token provided during oAuth steps
    
    // If you haven't done it yet, please follow the Guzzle official documentation for installing the client 
    // https://docs.guzzlephp.org/en/stable/overview.html#installation
    
    // Set your client for querying Akeneo API as follows
    $client = new \GuzzleHttp\Client([
        'base_uri' => $pimUrl,
        'headers' => ['Authorization' => 'Bearer ' . $appToken],
    ]);
    

    // Install the node-fetch library by following the official documentation:
    // https://www.npmjs.com/package/node-fetch
    
    import fetch from 'node-fetch';
    

#1. Get the PIM structure by fetching a channel from API

Workflow

synchronisation steps

Collect channel from PIM API:


    const API_URL = '/api/rest/v1/channels/%s';
    
    // Your own channel
    $channelCode = 'ecommerce';
    
    // Make an authenticated call to the API
    $response = $client->get(
    	sprintf(API_URL, $channelCode)
    );
    
    // Convert json response to array
    $channel = json_decode($response->getBody()->getContents(), true);
    

    const pimUrl = 'https://url-of-your-pim.com';
    const accessToken = 'your_app_token'; // Token provided during oAuth steps
    
    const channelCode = 'ecommerce';
    
    const response = await fetch(`${pimUrl}/api/rest/v1/channels/${channelCode}`, {
      headers: {
        'Authorization': `Bearer ${accessToken}`
      }
    });
    
    const channel = await response.json();
    

The retrieved channel resource looks like this:


    var_export($channel);
    
    // Output
    [
        'code' => 'ecommerce',
        'currencies' => [
            'USD',
            'EUR',
        ],
        'locales' => [
            'de_DE',
            'en_US',
            'fr_FR',
        ],
        'category_tree' => 'master',
        'conversion_units' => [],
        'labels' => [
            'en_US' => 'Ecommerce',
            'de_DE' => 'Ecommerce',
            'fr_FR' => 'Ecommerce',
        ],
    ]
    

    console.log(channel);
    
    // Output
    {
        code: 'ecommerce',
        currencies: [
            'USD',
            'EUR'
        ],
        locales: [
            'de_DE',
            'en_US',
            'fr_FR'
        ],
        category_tree: 'master',
        conversion_units: {},
        labels: {
            en_US: 'Ecommerce',
            de_DE: 'Ecommerce',
            fr_FR: 'Ecommerce'
        }
    }
    

#2. Store the PIM structure

We advise storing in your App locales, currencies, and root category.

  • Locales will allow filtering many localizable resource labels, and parsing product attribute values,
  • Currencies will be used to parse product values price attribute type,
  • Root category property will allow retrieving the whole category tree linked to the channel.

    storeCurrencies($channel['currencies']);
    storeLocales($channel['locales']);
    storeCategoryTree($channel['category_tree']);
    

    storeCurrencies(channel.currencies);
    storeLocales(channel.locales);
    storeCategoryTree(channel.category_tree);
    
Next Step
Well done! Keep digging into the “App workflow” and follow the next tutorial!