Sending Product API from Server
Description
When transferring the product database via Product API, there may be cases when the page of an out-of-stock product becomes unavailable.
In such a case, users cannot access it, and, accordingly, the Product API method event cannot be sent. This means that such a product will remain in stock on the Retail Rocket platform.
To avoid this problem, you need to configure sending data from the server for such products, with information that the product is no longer in stock.
Example
The server must send a POST request with product information. The information in the $data_string variable must be in JSON format and identical to the information in the retailrocket.products.post tracking code on the website.
If the Retail Rocket system successfully processes the request, the response should have a 200/204 status.
PHP code example:
- Without Grouped Products
- With Grouped Products
$data_string = '{
"id": 67998,
"name": "ITEM NAME",
"description": "ITEM DESCRIPTION",
"price": 790,
"pictureUrl": "LINK TO PICTURE",
"url": "LINK TO ITEM",
"isAvailable": false,
"categoryPaths": [
"PATH/TO/CATEGORY"
],
"stockId": "Madrid"
}';
$ch = curl_init('https://cdn.retailrocket.net/api/1.0/partner/<PARTNER_ID>/products/<PRODUCT_ID>');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_exec($ch);
$result = curl_getinfo($ch);
print_r($result);
$data_string = '{
"groupId": 67998,
"name": "ITEM NAME",
"description": "ITEM DESCRIPTION",
"price": 790,
"pictureUrl": "LINK TO PICTURE",
"url": "LINK TO ITEM",
"isAvailable": false,
"categoryPaths": [
"PATH/TO/CATEGORY"
],
"products": {
"679981": {
"isAvailable": false
},
"679982": {
"isAvailable": false
}
}
}';
$ch = curl_init('https://cdn.retailrocket.net/api/1.0/partner/<PARTNER_ID>/productsgroup/<PRODUCT_GROUP_ID>');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_exec($ch);
$result = curl_getinfo($ch);
print_r($result);
Where <PARTNER_ID> is the store's partnerId