Getting Started

On this page you can see a full example of using the Kaufland marketplace API to complete a simple task: listing a product for sale.

We assume you are already registered as a Kaufland marketplace seller and you want to offer a product for sale: a cat scratching post.

Note: In this example, we will assume that other sellers are already offering the product for sale on the Kaufland marketplace. If this is a completely new product for Kaufland marketplace, the process is a bit more complicated. You can read the full documentation for it on the Managing Product Data page.

Defining the offer JSON

The Kaufland marketplace API accepts JSON-formatted data, so you'll need to create a JSON object that represents the scratching posts you have. Here's the JSON we will use for our scratching posts:

{
	"ean": "4011905437873",
	"condition": "new",
	"listing_price": 4550,
	"minimum_price": 3990,
	"amount": 9,
	"note": "Important notes for the customer",
    "delivery_time_min": 3,
	"delivery_time_max": 8,
	"location": "DE"
}

For explanations of what each property means, see the Updating inventory with the REST API section of the Managing Inventory page.

Uploading the JSON

Now that we know what our JSON object should look like, we need to send it to the Kaufland marketplace through the REST API. We can use the below PHP code, which includes the signRequest function from the REST API documentation page.

Note: you will need the API keys from your API settings page to set the $clientKey and $secretKey in the example code.

<?php

function signRequest($method, $uri, $body, $timestamp, $secretKey)
{
	$string = implode("\n", [
		$method,
		$uri,
		$body,
		$timestamp,
	]);

	return hash_hmac('sha256', $string, $secretKey);
}

$baseUrl = 'https://sellerapi.kaufland.com/v2';

// Credentials for the API
$clientKey = '35f5dba43b471cd2ad28fd68e4825e2b';
$secretKey = 'b3575f222f7b768c25160b879699118b331c6883dd6010864b7ead130be77cd5';

// Define the POST data
$data = [
	"ean"           => "9780470527580",
	"condition"     => "new",
	"listing_price" => 4550,
	"minimum_price" => 3990,
	"amount"        => 9,
	"delivery_time_min": 3,
	"delivery_time_max": 8,
	"location"      => "DE"
];

$jsonData = json_encode($data);

// We're adding a new unit
$uri = $baseUrl . '/units/';

// Current Unix timestamp in seconds
$timestamp = time();

// Name of your partner solution
$userAgent = 'test'

// Define all the mandatory headers
$headers = [
    'Accept: application/json',
    'Shop-Client-Key: ' . $clientKey,
    'Shop-Timestamp: ' . $timestamp,
    'Shop-Signature: ' . signRequest('POST', $uri, $jsonData, $timestamp, $secretKey),
	'User-Agent: ' . $userAgent,
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);

$response = curl_exec($ch);
list($header, $body) = explode("\r\n\r\n", $response, 2);
print("$header\n\n");

$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print("HTTP Response Code: $responseCode\n");

If you run this script, it will output all of the HTTP headers received from the server, as well as the line HTTP Response Code: 201, meaning the data was saved successfully. For this request we are only interested in the HTTP code, not the body of the response, because the POST endpoints in the REST API respond with an empty body. Additionally, you'll see that the Location header was sent, with a value like /units/151177892008/. This is the URL of the new unit (i.e. offer) you have just created.

Next Step

Now that you've seen a simple example of how the REST API works, go on to the Overview Page to learn how the pieces of the Kaufland marketplace API fit together.