Example 1 - Simple Export
Introduction and data structure
This first example shows the simple export through the API of all the items in visible status from the PIM account.
Let's start by creating a

On the first page of the connector, the

On the

In this example we will only connect the English language and will only send items which are set as visible.
The parameter

When the parameters are configured as in the screenshot, neither the empty categories nor the multi-language titles will be exported.
Once the connector parameters in the first tab are configured, it is time for the next step: the
In our example, we will select a few fields from each of the tables.
In

In the

For the

Saving all the settings, you create the connector which is now ready for the first call.

Once the connector is created, you can choose the items to export. We did not apply any filters in this example, except the status of the items.
In the section

We now choose five products (randomly) and, among those, only two with variants (six variants in total):

It is important that the 16 variants are set as visible:

Code
The code is essential for the connection. In this case, we are going to see an example of how to export the desired items through the SL API.
We start by creating a

We have saved the connector code in the $connector_id parameter and its key in the $secret_key parameter.
It is now time to make a call to get_info() function of the class. This function extracts all the data configured in the connector and saves it locally.
As a parameter of the function itself we have submitted the value of $last_update. This parameter corresponds to the UNIX date of the last synchronization and is saved after every synchronization, ready to be used in the function call on the next synchronization.
As it is the first sync in our example, we set the parameter as 0.
Through the has_response_error() function we can check if the API has returned any error, and we can now print the following relevant information using these SDK functions:
- The API version is through the get_response_api_version() function.
- UNIX date of the exact time of the API call with the get_response_time() function.
- The default language of the PIM by calling the get_response_default_language() function.
Thanks to the
<?php
define('LOC_BASE', dirname(__FILE__) . '/');
require(LOC_BASE.'SalesLayer-Conn.php');
require(LOC_BASE.'lib/nice_r-master/Nicer.php');
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<link rel="stylesheet" type="text/css" href="lib/nice_r-master/nice_r.css?version=<?php echo filemtime(LOC_BASE.'lib/nice_r-master/nice_r.css'); ?>"/>
<script type="text/javascript" src="lib/nice_r-master/nice_r.js?version=<?php echo filemtime(LOC_BASE.'lib/nice_r-master/nice_r.js'); ?>"></script>
</head>
<body>
<?php
//SL conector credentials
$connector_id = 'CN12347H3308C4486';
$secret_key = '7aeb575d9bf15bfa238e8f01842417a2';
$last_update= "0";
//Create object with the credentials on the connector in S
$SLConn = new SalesLayer_Conn ($connector_id, $secret_key);
//API call to export the information
$SLConn->get_info($last_update);
if ($SLConn->has_response_error()) {
echo "<h4>Error:</h4>\n\n Code: ".$SLConn->get_response_error().
"<br>\nMessage: ". $SLConn->get_response_error_message();
} else {
echo "<h4>Response OK</h4>\n".
"<p>".
"API version: <b>". $SLConn->get_response_api_version() ."</b><br />\n".
"Time: <b>". $SLConn->get_response_time('unix') ."</b><br/>\n".
"Default language: <b>". $SLConn->get_response_default_language() ."</b><br/><br />\n".
"</p>";
//Print response from API
$n = new Nicer($SLConn->get_response_table_data());
$n->render();
echo "<hr/>";
}
?>
</body>
</html>
Execution and its results
These are the results after running the code script:

In our example, we set 14 categories, 5 products, and 16 variants as visible but it has returned:
- 11 categories
- 5 products
- 6 variants
This is the result of our settings in the connector parameters since we intended to avoid exporting empty categories. Therefore, categories without any associated products will not be exported and only direct categories and the ones depending on them will be exported.

Even if the variants are set as visible, they will not be exported if they are not linked to parent products that have also been exported. Only 2 of the 5 products that we set as visible have variants. As a result, only those variants linked to these two products will be exported.
In greater detail, we can also confirm the exported tables and fields. In the category table we can see the four fields that we have selected in the connector:

In the product table we can find the following:

The variant table will look like in the screenshot below:
