Review, Review media and Rating API
This API allows users to manage reviews for products, including creating, updating, deleting, and retrieving reviews. It supports filtering, sorting, and marking reviews as helpful.
Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/product/review/list/ |
Retrieve a list of reviews. |
| POST | /api/v1/product/review/add/ |
Create a new review. |
| PUT | /api/v1/product/review/edit/<str:pk>/ |
Update an existing review. |
| DELETE | /api/v1/product/review/remove/<str:pk>/ |
Delete a review. |
| POST | /api/v1/product/review/<str:review_id>/helpful/ |
Mark a review as helpful. |
ReviewMediaListView
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/product/review/all/media/ |
Retrieve review media details. |
Review API
1. List Reviews
Endpoint
- URL:
/api/v1/product/review/list/ - Method:
GET - Permission Required:
AllowAny
Description
Retrieve all reviews with pagination. Reviews can be filtered by product ID, rating, and other criteria. Sorting by helpful count or rating is also supported.
Query Parameters
product_id(Optional): Filter reviews for a specific product.rating(Optional): Filter reviews by rating (integer, e.g., 1, 2, 3, etc.).media_only(Optional): If true, retrieves reviews that include media files.sort_by_helpful(Optional): If true, sorts reviews by helpful count in descending order.sort_by_rating(Optional): Sort reviews by rating:- high: High to low
- low: Low to high
Example Query
GET /api/v1/reviews/?product_id=101&rating=5&media_only=true&sort_by_helpful=true&page=1&page_size=10
Request Payload
This endpoint does not require a request payload.
Response Examples
Success
{
"count": 25,
"next": "http://api.example.com/api/v1/reviews/?page=2",
"previous": null,
"results": [
{
"id": 1,
"user": "john_doe",
"product_id": 101,
"rating": 5,
"review_text": "Excellent product!",
"review_image1": "http://api.example.com/media/review1.jpg",
"review_video": null,
"helpful_count": 10,
"created_at": "2024-12-01T10:00:00Z"
},
{
"id": 2,
"user": "jane_doe",
"product_id": 102,
"rating": 4,
"review_text": "Very good quality!",
"review_image1": null,
"review_video": "http://api.example.com/media/review2.mp4",
"helpful_count": 5,
"created_at": "2024-11-30T14:45:00Z"
}
]
}
2. Create a Reviews
Endpoint
- URL:
/api/v1/product/review/add/ - Method:
POST - Permission Required:
IsAuthenticated
Description
Allows an authenticated user to create a new review for a product.
Request Payload
{
"product_id": 101,
"rating": 5,
"review_text": "Excellent product!",
"review_image1": "image_url_1",
"review_video": "video_url"
}
Response Examples
Success
{
"id": 1,
"user": "john_doe",
"product_id": 101,
"rating": 5,
"review_text": "Excellent product!",
"review_image1": "http://api.example.com/media/review1.jpg",
"review_video": null,
"helpful_count": 0,
"created_at": "2024-12-01T10:00:00Z"
}
Error
{
"detail": "Authentication is required to add a review."
}
3. Update Reviews
Endpoint
- URL:
/api/v1/product/review/edit/<str:pk>/ - Method:
PUT - Permission Required:
IsAuthenticated
Description
Allows an authenticated user to create a new review for a product.
Request Payload
{
"product_id": 101,
"rating": 5,
"review_text": "Excellent product!",
"review_image1": "image_url_1",
"review_video": "video_url"
}
Response Examples
Success
{
"id": 1,
"user": "john_doe",
"product_id": 101,
"rating": 5,
"review_text": "Excellent product!",
"review_image1": "http://api.example.com/media/review1.jpg",
"review_video": null,
"helpful_count": 0,
"created_at": "2024-12-01T10:00:00Z"
}
Error
{
"detail": "Authentication is required to add a review."
}
4. Delete Reviews
Endpoint
- URL:
/api/v1/product/review/remove/<str:pk>/ - Method:
DELETE - Permission Required:
IsAuthenticated
Description
Allows the review's author to delete the review.
Request Payload
This API does not require any request payload.
Response Examples
Success
{
"detail": "Review deleted successfully."
}
Error
{
"detail": "You do not have permission to delete this review."
}
5. Mark a Review as Helpful
Endpoint
- URL:
/api/v1/product/review/<str:review_id>/helpful/ - Method:
POST - Permission Required:
IsAuthenticated
Description
Marks a review as helpful. Only authenticated users can perform this action, and a user can mark a review as helpful only once.
Request Payload
This API does not require any request payload.
Response Examples
Success
{
"detail": "Marked as helpful successfully.",
"helpful_count": 11
}
Error
{
"detail": "You have already marked this review as helpful."
}
Review media API
1. Retrieve Review Media Details
Endpoint
- URL:
/api/v1/product/review/all/media/ - Method:
GET - Permission Required:
AllowAny
Description
Retrieve media details (images and videos) for all reviews.
Request Payload
This API does not require any request payload.
Response Examples
[
{
"review_id": 101,
"images": [
"http://api.example.com/media/review1.jpg",
"http://api.example.com/media/review2.jpg"
],
"videos": [
"http://api.example.com/media/review1.mp4"
]
},
{
"review_id": 102,
"images": [],
"videos": []
}
]