# Product Review

## Write a review

<mark style="color:green;">`POST`</mark> `‎https://<domain>/<api prefix>/<version>/commerce/product/product-review/`

Using this API users can write a review for a previously purchased product.

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string |                     |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer Access Token |

#### Request Body

| Name                                      | Type   | Description                   |
| ----------------------------------------- | ------ | ----------------------------- |
| comment<mark style="color:red;">\*</mark> | string | review comment                |
| bundle<mark style="color:red;">\*</mark>  | number | product bundle id (unique id) |
| stars<mark style="color:red;">\*</mark>   | number | no. of stars given            |

{% tabs %}
{% tab title="200 " %}

```
HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```javascript
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**

```typescript
<?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;
```

#### Error Responses

| Status code | Error Type       | Field   | Description                                                                                              |
| ----------- | ---------------- | ------- | -------------------------------------------------------------------------------------------------------- |
| 400         | Validation Error | bundle  | <p>Bundle id is required.</p><p>This field may not be blank.</p><p>Product with bundle id not exist.</p> |
| 400         | Validation Error | comment | comment is required                                                                                      |
| 400         | Validation Error | stars   | stars count is required                                                                                  |

## Get Review Status

<mark style="color:blue;">`GET`</mark> `‎https://<domain>/<api prefix>/<version>/commerce/product/product-review/`

This endpoint will return how many times the user purchased this product previously.

#### Query Parameters

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| bundle\_id | string |             |

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer Access Token |

{% tabs %}
{% tab title="200 " %}

```
HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": 0
}
```

{% endtab %}
{% endtabs %}

#### Note:

All Reviews from different users of a product are fetched in product details api.

#### Sample Code

#### **Node**

```typescript
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

```typescript
<?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();
}
```

#### Error Responses

| Status Code | Error Type       | Field      | Description                                                                                              |
| ----------- | ---------------- | ---------- | -------------------------------------------------------------------------------------------------------- |
| 400         | Validation Error | bundle\_id | <p>Bundle id is required.</p><p>This field may not be blank.</p><p>Product with bundle id not exist.</p> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api.epixelsoftware.help/product-review.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
