Using this API users can write a review for a previously purchased product.
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://<domain>/<api prefix>/<version>/commerce/product/product-review/',
'headers': {
'apikey': '<api key>',
'Authorization': 'Bearer <access token>',
},
formData: {
'comment': '<comment>',
'stars': '<star count>',
'bundle': '<bundle id>'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/commerce/product/product-review/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('bundle' => '<bundle_id>','comment' => '<>comment','stars' => '<stars_count>'),
CURLOPT_HTTPHEADER => array(
'apikey: <apikey>',
'Authorization: Bearer <access token>',
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
This endpoint will return how many times the user purchased this product previously.
All Reviews from different users of a product are fetched in product details api.
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://<domain>/<api prefix>/<version>/commerce/product/product-review/',
'headers': {
'apikey': '<api key>',
'Authorization': 'Bearer <access token>',
'Cookie': 'defult_store_slug=admin_store; store_user=admin_store'
},
formData: {
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://<domain>/<api prefix>/<version>/commerce/product/product-review/');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'apikey' => '<api key>',
'Authorization' => 'Bearer <access token>',
'Cookie' => 'defult_store_slug=admin_store; store_user=admin_store'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}