hitmeister/api-sdk

Kaufland.de onlineshop API SDK for PHP

1.54.0 2023-04-25 11:19 UTC

README

Latest Stable Version Coverage Status Total Downloads

PHP client for Kaufland.de Onlineshop API.

Install

Via Composer

$ composer require hitmeister/api-sdk

Via GitHub

$ git clone git@github.com:hitmeister/api-sdk-php.git

Quickstart

This section will give you a quick overview of the client and how the major functions work.

Create client

Before starting, you will need the API keys from your API settings page. Also please provide the name of your partner solution name to the setUserAgent() field.

Include the autoloader in your main project (if you haven’t already), and instantiate a new client.

require 'vendor/autoload.php';

use Hitmeister\Component\Api\ClientBuilder;

$client = ClientBuilder::create()
	->setClientKey('YOUR_CLIENT_KEY')
	->setClientSecret('YOUR_CLIENT_SECRET')
	->setUserAgent('YOUR_USER_AGENT')
	->build();

Namespaces overview

The client has a number of "namespaces", which generally expose API functionality. The namespaces correspond to the various API endpoints. This is a complete list of namespaces:

Retrieve the categories data

You can search for categories:

$categories = $client->categories()->find('handy');
foreach ($categories as $category) {
	echo "Category ID: {$category->id_category}\n";
	echo "Category Name: {$category->name}\n";
}

Or get the information about one of them:

$category = $client->categories()->get(1);
echo "Category ID: {$category->id_category}\n";
echo "Category Name: {$category->name}\n";

Retrieve the product data

Search for items:

$items = $client->items()->find('iphone');
foreach ($items as $item) {
	$eans = implode(',', $item->eans);
	echo "Item ID: {$item->id_item}\n";
	echo "Category ID: {$item->id_category}\n";
	echo "Title: {$item->title}\n";
	echo "EANs: {$eans}\n";
}

Also you can find the items by EAN:

$items = $client->items()->findByEan('0885909781652');

Send inventory data

According to the API documentation you have two options:

To upload your product data as CSV file

// Post the task to import your file. You will have the ID of the task.
$importFileId = $client->importFiles()
	->post('http://www.example.com/my_products.csv', 'PRODUCT_FEED');

// Retrieve the information about your task
$data = $client->importFiles()->get($importFileId);
echo "URL: {$data->uri}\n";
echo "Status: {$data->status}\n";

To update a single unit

// $result will be true or false
$result = $client->units()->update(10, ['condition' => 'new']);

Testing

$ composer test

License

The MIT License (MIT). Please see License File for more information.