Welcome to the REST API of your webshop. We assume you know the basics of a REST API and know how it works.
With the information below you will be able to create a basic request.
A Basic http request
Step 1. Creating API Credentials
To gain access to the API you will need an API key and an API secret. These can be created in your webshop's backend. These can be found in "My web shop / Settings / API settings". If these settings are not visible in your backend, make sure you've installed the API app from the App Store.
Step 2. Hashing and Authentication
Creating the hash
Below we provided an example to create the hash in php.
You need a few variables to create a valid hash:
$sPublic_key: The "Public key" or "Api key" can be retrieved in the webshop. This should be the same as the header 'x-public'.
$sSecret_key: The "Secret key" or "Api secret" can be retrieved in the webshop.
$sMethod: HTTP method in uppercase (ie: GET, POST, PATCH, DELETE)
$sData: The data that is submitted with the request. Only used in post, patch requests.
$sUri: The request URI minus the domain name.(ie: /api/rest/v1/products/)
$sTimeStamp: Current timestamp in ISO 8601 UTC time (ie: 2022-11-26T00:45:54Z).
PHP example code:
<?php
//Creating the hash
$sHashString = "$sPublic_key|$sMethod|$sUri|$sData|$sTimeStamp";
$sHash = hash_hmac('sha512', $sHashString, $sSecret_key);
?>
Headers
Each request requires the following three headers:
x-public
This field should contain the "Public key" or "Api key".
x-date
This field should contain the current timestamp in UTC format.
Note: this timestamp may not differ more than 5 minutes from server time.
x-hash
This header should contain the calculated hash. This hash should be calculated with HMAC using the SHA512 encryption.
PHP example code:
<?php
curl_setopt($rCurlHandler, CURLOPT_HTTPHEADER,
array(
"x-date: ". $sTimeStamp,
"x-hash: ". $sHash,
"x-public: ". $sPublic_key
)
);
?>
Note: Never submit the secret_key in any request! Only use the key to calculate a hash.
Step 3. Make API Calls
Once you have created your API credentials, you can create API calls.
Get a list of products
With the example code below you are able to get a list of products
PHP example code:
<?php
//The "Public key" or "Api key" can be retrieved in the webshop.
//This should be the same as the header 'x-public'.
$sPublic_key = '';
//The "Secret key" or "Api secret" can be retrieved in the webshop.
$sSecret_key = '';
//HTTP method in upppercase (ie: GET, POST, PATCH, DELETE)
$sMethod = 'GET';
//The data that is being posted to the resource (only with POST or PATCH methods)
$sData = null;
//The request URI minus the domain name
$sUri = '/api/rest/v1/products';
//The request domain without trailing slash
$sDomain = 'https://yourdomain.com';
//Set the time zone to utc
date_default_timezone_set('UTC');
$sTimeStamp = date('c');
//Creating the hash
$sHashString = "$sPublic_key|$sMethod|$sUri|$sData|$sTimeStamp";
$sHash = hash_hmac('sha512', $sHashString, $sSecret_key);
$rCurlHandler = curl_init();
curl_setopt($rCurlHandler, CURLOPT_URL, $sDomain.$sUri);
curl_setopt($rCurlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCurlHandler, CURLOPT_HTTPHEADER,
array(
"x-date: ". $sTimeStamp,
"x-hash: ". $sHash,
"x-public: ". $sPublic_key
)
);
$sOutput = curl_exec($rCurlHandler);
curl_close($rCurlHandler);
//Response : a list with objects of products
$oResponse = json_decode($sOutput);
?>
Post a product
With the example code below you are able to create a successful product post .
PHP example code:
<?php
//The "Public key" or "Api key" can be retrieved in the webshop.
//This should be the same as the header 'x-public'.
$sPublic_key = '';
//The "Secret key" or "Api secret" can be retrieved in the webshop.
$sSecret_key = '';
//HTTP method in upppercase (ie: GET, POST, PATCH, DELETE)
$sMethod = 'POST';
//The request URI minus the domain name
$sUri = '/api/rest/v1/products';
//The request domain without trailing slash
$sDomain = 'https://yourdomain.com';
//Set the time zone to utc
date_default_timezone_set('UTC');
$sTimeStamp = date('c');
//Data fields
$aData = array(
"name" => "test product",
"vatrate" => 21,
"price" => "11.95",
"discount" => "1.95",
"package_id" => 1
);
//Datafields to Json
$sData = json_encode($aData);
$sHashString = "$sPublic_key|$sMethod|$sUri|$sData|$sTimeStamp";
$sHash = hash_hmac('sha512', $sHashString, $sSecret_key);
$rCurlHandler = curl_init();
curl_setopt($rCurlHandler, CURLOPT_URL, $sDomain.$sUri);
curl_setopt($rCurlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCurlHandler, CURLOPT_HTTPHEADER,
array(
"x-date: ". $sTimeStamp,
"x-hash: ". $sHash,
"x-public: ". $sPublic_key
)
);
curl_setopt($rCurlHandler, CURLOPT_POSTFIELDS, $sData);
curl_setopt($rCurlHandler, CURLOPT_CUSTOMREQUEST, $sMethod);
$sOutput = curl_exec($rCurlHandler);
//Response : a product object
$oResponse = json_decode($sOutput);
curl_close($rCurlHandler);
?>
Patching a product API Call PHP example code:
With the example code below you are able to change a product number for a specific resource Id.
Resource Id (ProductId) : 1234567890
Product number : PROD001
PHP example code:
<?php
//The "Public key" or "Api key" can be retrieved in the webshop.
//This should be the same as the header 'x-public'.
$sPublic_key = '';
//The "Secret key" or "Api secret" can be retrieved in the webshop.
$sSecret_key = '';
//HTTP method in upppercase (ie: GET, POST, PATCH, DELETE)
$sMethod = 'PATCH';
//The request URI minus the domain name
$sUri = '/api/rest/v1/products/1234567890';
//The request domain without trailing slash
$sDomain = 'https://yourdomain.com';
//Set the time zone to utc
date_default_timezone_set('UTC');
$sTimeStamp = date('c');
//Data fields
$aData = array('productnumber' => 'PROD001');
//Datafields to Json
$sData = json_encode($aData);
//Creating the hash
$sHashString = "$sPublic_key|$sMethod|$sUri|$sData|$sTimeStamp";
$sHash = hash_hmac('sha512', $sHashString, $sSecret_key);
$rCurlHandler = curl_init();
curl_setopt($rCurlHandler, CURLOPT_URL, $sDomain.$sUri);
curl_setopt($rCurlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCurlHandler, CURLOPT_HTTPHEADER,
array(
"x-date: ". $sTimeStamp,
"x-hash: ". $sHash,
"x-public: ". $sPublic_key
)
);
curl_setopt($rCurlHandler, CURLOPT_POSTFIELDS, $sData);
curl_setopt($rCurlHandler, CURLOPT_CUSTOMREQUEST, $sMethod);
//Response :
$oResponse = curl_exec($rCurlHandler);
curl_close($rCurlHandler);
?>
Get a product by product number
With the example code below you are able to search for a product with product number: PROD001. See the section on Query parameters for more extensive explaination on this subject.
PHP example code:
<?php
//The "Public key" or "Api key" can be retrieved in the webshop.
//This should be the same as the header 'x-public'.
$sPublic_key = '';
//The "Secret key" or "Api secret" can be retrieved in the webshop.
$sSecret_key = '';
//HTTP method in upppercase (ie: GET, POST, PATCH, DELETE)
$sMethod = 'GET';
//The request URI minus the domain name
$sUri = '/api/rest/v1/products/?productnumber=PROD001';
//The request domain without trailing slash
$sDomain = 'https://yourdomain.com';
//Set the time zone to utc
date_default_timezone_set('UTC');
$sTimeStamp = date('c');
$rCurlHandler = curl_init();
curl_setopt($rCurlHandler, CURLOPT_URL, $sDomain.$sUri);
curl_setopt($rCurlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCurlHandler, CURLOPT_HTTPHEADER,
array(
"x-date: ". $sTimeStamp,
"x-hash: ". $sHash,
"x-public: ". $sPublic_key
)
);
curl_setopt($rCurlHandler, CURLOPT_CUSTOMREQUEST, $sMethod);
//Response : a product object with product number PROD001
$oResponse = curl_exec($rCurlHandler);
curl_close($rCurlHandler);
?>
Delete a product by resource id
With the example code below you are able delete a product with resource id 1234567890.
PHP example code:
<?php
//The "Public key" or "Api key" can be retrieved in the webshop.
//This should be the same as the header 'x-public'.
$sPublic_key = '';
//The "Secret key" or "Api secret" can be retrieved in the webshop.
$sSecret_key = '';
//HTTP method in upppercase (ie: GET, POST, PATCH, DELETE)
$sMethod = 'DELETE';
//The request URI minus the domain name
$sUri = '/api/rest/v1/products/1234567890';
//The request domain without trailing slash
$sDomain = 'https://yourdomain.com';
//Set the time zone to utc
date_default_timezone_set('UTC');
$sTimeStamp = date('c');
$rCurlHandler = curl_init();
curl_setopt($rCurlHandler, CURLOPT_URL, $sDomain.$sUri);
curl_setopt($rCurlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCurlHandler, CURLOPT_HTTPHEADER,
array(
"x-date: ". $sTimeStamp,
"x-hash: ". $sHash,
"x-public: ". $sPublic_key
)
);
curl_setopt($rCurlHandler, CURLOPT_CUSTOMREQUEST, $sMethod);
$sOutput = curl_exec($rCurlHandler);
curl_close($rCurlHandler);
?>
API Browser
There is also an API Browser available that lets you browse through the API and it's content. The browser should give you a good
idea of how the API works and what's possible.
The API Browser can be found here:
https://demo.ccvshop.nl/API/Docs/Browser.php