Skip to main content
POST
/
api
/
review
Create Review
curl --request POST \
  --url https://api.example.com/api/review \
  --header 'Content-Type: application/json' \
  --data '
{
  "productId": "<string>",
  "rating": 123,
  "comment": "<string>"
}
'
{
  "statusCode": 201,
  "message": "Review added successfully",
  "data": {
    "userId": "user123",
    "productId": "12345",
    "rating": 5,
    "comment": "Great product! Highly recommended."
  }
}

Authentication

This endpoint requires JWT authentication. Include your bearer token in the Authorization header.
Authorization: Bearer <your_token>

Request Body

productId
string
required
The ID of the product to review. The product must exist in the database.
rating
number
required
The rating for the product. Must be between 1 and 5.
comment
string
required
The review comment text.

Response

statusCode
number
HTTP status code of the response
message
string
Response message
data
object
The created review data

Example Request

curl -X POST https://api.example.com/api/review \
  -H "Authorization: Bearer <your_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "productId": "12345",
    "rating": 5,
    "comment": "Great product! Highly recommended."
  }'

Example Response

{
  "statusCode": 201,
  "message": "Review added successfully",
  "data": {
    "userId": "user123",
    "productId": "12345",
    "rating": 5,
    "comment": "Great product! Highly recommended."
  }
}

Notes

  • The review is automatically associated with the authenticated user
  • After adding a review, the product’s average rating is automatically updated
  • The rating must be an integer between 1 and 5
  • All fields are required

Build docs developers (and LLMs) love