List Product Comments
Retrieves a list of all product comments with filtering, searching, and ordering capabilities.
HTTP Request
GET/api/products/comments
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | 10 | Number of results to return per page |
| offset | integer | 0 | Number of results to skip before returning results |
| search | string | — | Search term to filter results by (`id`, `content`, `product__id`, `product__name`, `product_slug`, `user__id`, `user__username`, `user__mobile_number`, `user__first_name`, `user__last_name`) |
| ordering | string | -created_at | Field to order results by (`id`, `user`, `product`, `rating`, `is_published`, `updated_at`, `created_at`) |
| is_anonymous | boolean | — | Filter by anonymous status |
| is_published | boolean | — | Filter by published status |
| rating_min | integer | — | Minimum rating filter (1-5) |
| rating_max | integer | — | Maximum rating filter (1-5) |
| product | integer | — | Filter by specific product ID |
| product_in | string | — | Filter by multiple product IDs (comma-separated: 1,2,3) |
| user | integer | — | Filter by specific user ID |
| user_in | string | — | Filter by multiple user IDs (comma-separated: 1,2,3) |
| id_min | integer | — | Minimum ID filter |
| id_max | integer | — | Maximum ID filter |
| created_date | string | — | Filter by creation date (e.g., 2023-01-01) |
| updated_date | string | — | Filter by last updated date (e.g., 2023-01-01) |
| created_from | string | — | Filter by creation date range start |
| created_to | string | — | Filter by creation date range end |
| updated_from | string | — | Filter by last updated date range start |
| updated_to | string | — | Filter by last updated date range end |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# List all product comments
4response = requests.get('http://www.example.com/api/products/comments',
5 headers={'Authorization': 'Token <your_api_key>'}
6)
7print(response.json())
8
9# Search for comments with filters
10response = requests.get('http://www.example.com/api/products/comments', params={
11 'search': 'great product',
12 'is_published': True,
13 'rating_min': 4,
14 'ordering': '-created_at',
15 'limit': 20
16}, headers={'Authorization': 'Token <your_api_key>'})
17print(response.json())
18
19# Filter by specific product and rating range
20response = requests.get('http://www.example.com/api/products/comments', params={
21 'product': 5,
22 'rating_min': 3,
23 'rating_max': 5,
24 'is_published': True
25}, headers={'Authorization': 'Token <your_api_key>'})
26print(response.json())1# List all product comments
2curl "http://www.example.com/api/products/comments" -H "Authorization: Token <your_api_key>"
3
4# Search with filters
5curl "http://www.example.com/api/products/comments?search=great%20product&is_published=true&rating_min=4&ordering=-created_at&limit=20" \
6-H "Authorization: Token <your_api_key>"
7
8# Filter by specific product and rating range
9curl "http://www.example.com/api/products/comments?product=5&rating_min=3&rating_max=5&is_published=true" \
10-H "Authorization: Token <your_api_key>"Status Codes
| Code | Description |
|---|---|
| 200 | Product comments retrieved successfully |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | integer | Unique ID of the comment |
| rating | integer | Rating given (1-5: Worst, Bad, Average, Good, Best) |
| content | string | Comment content (max 500 characters) |
| is_anonymous | boolean | Whether the comment is posted anonymously |
| is_published | boolean | Whether the comment is published |
| user_data | object | User details (read-only) |
| product_data | object | Product details (read-only) |
| truncated_content | string | Shortened version of content |
| created_at | string (ISO 8601) | Timestamp when comment was created |
| updated_at | string (ISO 8601) | Timestamp when comment was last updated |
User Data Structure
| Field | Type | Description |
|---|---|---|
| id | integer | Unique ID of the user |
| username | string | Username of the user |
| full_name | string | Full name of the user |
| avatar | string | URL of the user avatar image |
Product Data Structure
| Field | Type | Description |
|---|---|---|
| id | integer | Unique ID of the product |
| name | string | Name of the product |
Notes
- Rating scale: 1=Worst, 2=Bad, 3=Average, 4=Good, 5=Best
- Comments can be filtered by publication status to show only approved content
- Anonymous comments hide user identification but retain moderation capabilities
- All timestamps are in ISO 8601 format (e.g., "2023-01-01T12:00:00Z")