Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JuanSCaicedo/Api-Ecommerce/llms.txt

Use this file to discover all available pages before exploring further.

Reviews are attached to individual products and to the authenticated user who writes them. They appear on the product detail page (GET /api/ecommerce/product/{slug}) alongside a computed rating distribution that shows the percentage breakdown across all five star levels. Both creating and updating a review calls Cache::flush() so that the product page immediately reflects the new data.

POST /api/ecommerce/reviews

Creates a new product review. Requires a valid Bearer token. The user_id is set server-side from the token — clients must not supply it.
curl --request POST \
  --url https://your-domain.com/api/ecommerce/reviews \
  --header "Authorization: Bearer <token>" \
  --header "Content-Type: application/json" \
  --data '{
    "product_id": 42,
    "message": "Excellent sound quality, very comfortable to wear for long sessions.",
    "rating": 5
  }'

Body

product_id
integer
required
The ID of the product being reviewed.
message
string
required
The review text. No maximum length is enforced at the API level; apply frontend validation as needed.
rating
integer
required
Star rating from 1 (worst) to 5 (best). The API stores the raw integer — enforce the 1–5 range on the client side.

Response

{
  "review": {
    "id": 9,
    "user_id": 12,
    "product_id": 42,
    "message": "Excellent sound quality, very comfortable to wear for long sessions.",
    "rating": 5,
    "created_at": "2024-06-11T14:22:00.000000Z",
    "updated_at": "2024-06-11T14:22:00.000000Z"
  }
}
review
object
The newly created review model, including the server-assigned id, user_id, and timestamps.
Creating a review calls Cache::flush(), which invalidates all cached responses — including the product detail page, the storefront home feed, and the menu. The next request to GET /api/ecommerce/product/{slug} will rebuild the cache with the updated review list and rating distribution.

PUT /api/ecommerce/reviews/

Updates an existing review. Requires a valid Bearer token. The server does not re-verify ownership — ensure your frontend only allows users to edit their own reviews.
curl --request PUT \
  --url https://your-domain.com/api/ecommerce/reviews/9 \
  --header "Authorization: Bearer <token>" \
  --header "Content-Type: application/json" \
  --data '{
    "message": "Still great after 3 months of daily use. Build quality is excellent.",
    "rating": 5
  }'

Path parameters

ParameterTypeDescription
idintegerThe review ID to update.

Body

message
string
Updated review text.
rating
integer
Updated star rating (1–5).

Response

{
  "review": {
    "id": 9,
    "user_id": 12,
    "product_id": 42,
    "message": "Still great after 3 months of daily use. Build quality is excellent.",
    "rating": 5,
    "created_at": "2024-06-11T14:22:00.000000Z",
    "updated_at": "2024-06-12T08:05:00.000000Z"
  }
}
Updating a review also calls Cache::flush(), clearing all cached storefront data for the same reason as creating a review.

Rating Distribution

When you fetch a product via GET /api/ecommerce/product/{slug}, the response includes a rating_distribution object that summarises the spread of star ratings across all reviews for that product.
{
  "rating_distribution": {
    "5": 60.00,
    "4": 25.00,
    "3": 10.00,
    "2": 5.00,
    "1": 0.00
  }
}
Each key ("1" through "5") maps to a percentage of total reviews at that star level, rounded to 2 decimal places. The percentages are calculated as:
percentage = (count_at_star / total_reviews) × 100
When a product has no reviews, all values are 0.00.
KeyMeaning
"5"Percentage of reviews that gave 5 stars
"4"Percentage of reviews that gave 4 stars
"3"Percentage of reviews that gave 3 stars
"2"Percentage of reviews that gave 2 stars
"1"Percentage of reviews that gave 1 star
The avg_reviews and count_reviews fields on the product resource give the overall average and total count:
{
  "avg_reviews": 4.75,
  "count_reviews": 8
}
These aggregate values are computed from the reviews_avg and reviews_count accessors on the Product model and are available on every ProductEcommerceResource response.

Build docs developers (and LLMs) love