This is a PHP package for Plentymarkets new REST API. The API is relatively new at time of writing (March 2017), so not everything might work correctly and this package might also be out of date at some point.
I'm not in anyway affiliated with Plentymarkets, nor do I get paid for this by anybody. As it says in the license, this software is 'as-is'. If you want/need more features, open a GitHub ticket or write a pull request. I'll do my best :) That said, I don't work for the company I developed this for anymore, so if you have any interest in becoming a contributor on this repo, let me know.
You can find the Plentymarkets documentation here:
Available via composer on Packagist:
composer require repat/plentymarkets-rest-client
use repat\PlentymarketsRestClient\PlentymarketsRestClient;
// path to store the configuration in
$configFilePath = ".plentymarkets-rest-client.config.php";
// $config only has to be set once like this
$config = [
"username" => "PM_USERNAME",
"password" => "PM_PASSWORD",
"url" => "https://www.plentymarkets-system.tld",
];
// Handle (Guzzle) Exceptions yourself - optional 3rd parameter
$handleExceptions = PlentymarketsRestClient::HANDLE_EXCEPTIONS; // true
$handleExceptions = PlentymarketsRestClient::DONT_HANDLE_EXCEPTIONS; // false (default)
// Init
$client = new PlentymarketsRestClient($configFilePath, $config, $handleExceptions);
// After that just use it like so
$client = new PlentymarketsRestClient($configFilePath);
It's possible to use the 4 HTTP verbs like this
$client->get($path, $parameterArray);
$client->post($path, $parameterArray);
$client->put($path, $parameterArray);
$client->delete($path, $parameterArray);
// $parameterArray has to be a PHP array. It will be transformed into JSON automatically in case
// of POST, PUT and DELETE or into query parameters in case of GET.
// You don't _have_ to specify it, it will then just be empty
$parameterArray = [
"createdAtFrom" => "2016-10-24T13:33:23+02:00"
];
// $path is the path you find in the Plentymarkets documentation
$path = "rest/orders/";
It's also possible to use the function like this. It gives you more freedom, since you can specify the method and the $parameters given are directly given to the Guzzle object.
$client->singleCall("GET", $guzzleParameterArray);
Some endpoints, such as /rest/bi/raw-data/file
don't return JSON but a raw file. However, by default a single call tries to json_decode()
the response. You can disable it by setting the $jsonDecodeEnabled
flag to false
.
$client->setJsonDecodeEnabled(PlentymarketsRestClient::JSON_DECODE_DISABLED);
$handleExceptions
has been set to true
, in which case the exception will be handed throughjson_decode()
to allow for querying for raw files (thx dark-cms)str_contains
to PHPs stripos()
because it doesn't require ext-mbstring
(thx DanMan)danielstjules/stringy
dependency, copy over Laravels str_contains
insteadtrue
as 3rd parameterisAccessTokenValid()
(thx hochdruckspezialist)PATCH
(thx hepisec)www.
as it breaks subdomains (thx daniel-mannheimer)