Getting Started

On this page you can see a full example of using the real.de Onlineshop API to complete a simple task: listing an item for sale.

We assume you are already registered as a real.de Onlineshop marketplace seller and you want to offer an item for sale: a cat scratching post.

Note: In this example, we will assume that other sellers are already offering the item for sale on the real.de Onlineshop website. If this is a completely new product for real.de Onlineshop, 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 real.de Onlineshop 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 real.de Onlineshop 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://www.real.de/api/v1';

// 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();

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

$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 real.de Onlineshop API fit together.