Product Reviews APIs
There two (2) APIs for the product reviews:
- Add Product review
- Get Product reviews
1. Add Product review
Endpoint
POST /products/reviews/add
Payload
The payload properties and their respctive conditions are mentioned in code comments along below, please read the comments carefully. Here's an example review pauload.
1
2
3
4
5
6
7
8
9
{
"product_id": "64a59d5816b4c91fa1967b2e", // | Required | The respected product, the user want to add review for.
"rating": 4, // | Required | Any non-decimal number between 1 and 5, 1 and 5 inclusive.
"review": "The product quality is good but the delivery was a little late.", // | Optional | The review/comment of the user about the product. Max 500 characters.
"images": [ // | Optional | An array of image URLs. Maximum 5 images are allowed.
"https://example.com/image1.jpg",
"https://example.com/image2.jpg"
]
}Remember that if the rating value is provided in a decimal number, the server will automatically round it off to its next highest non-decimal value.
For example if rating's value is 3.2 or 3.7, it will be converted to 4.
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
success: true,
msg: "Thanks for your review! It would help others to know about the product.",
review: {
"_id": "6683df8f3985b340027b164a",
"user_id": "65ddb7496a09ca290bec88b2",
"images": [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg"
],
"product_id": "656a0cc84839597ecab95819",
"rating": 4,
"review": "The product quality is quite good and the delivery time is also as promised. I would recommend it!",
"createdAt": "2024-07-02T11:07:58.955Z",
"updatedAt": "2024-07-02T11:09:40.664Z"
"__v": 0,
}
}After adding a review successfully, a notification will be delivered to the user's notification inbox in category primary.
2. Get Product reviews
Endpoint
GET /products/reviews/get
Payload
There are 2 Query parameters for this API. You have to send a mandatory Query Parameter: product_id containing the id of the product. And an optional query parameter page, by default it's value will be considered 1 if not provided.
This API also has pagination with constant limit of 10.
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
"success": true,
"msg": "",
"reviews": [
{
"_id": "6683df8f3985b340027b164a",
"user_id": {
"_id": "65ddb7496a09ca290bec88b2",
"username": "_saad_",
"email": "binarshadsaad6@gmail.com",
"firstname": "Saad",
"gender": "male",
"lastname": "Bin Arshad"
},
"__v": 0,
"createdAt": "2024-07-02T11:07:58.955Z",
"images": [],
"product_id": "656a0cc84839597ecab95819",
"rating": 4,
"review": "The product quality is quite good and the delivery time is also as promised. I would recommend it!",
"updatedAt": "2024-07-02T11:09:40.664Z"
}
// Other 9 reviews if exist.
],
"total_pages": 1,
"total_reviews": 1, // In this case, only 1 review exists for this product.
"current_page": 1,
"limit": 10, // In this API, the limit will always be 10 and cannot be changed.
"average_rating": 4 // It will be the average rating i.e sum of all ratings devided by total number of reviews.
}