Create Product Comment
Creates a new product comment.
HTTP Request
POST/api/products/comments
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| content | String | Yes | Comment content (max 500 characters) |
| user | Integer | Yes | User ID who is posting the comment |
| product | Integer | Yes | Product ID being commented on |
| rating | Integer | No | Rating given (1-5, default: 3) |
| is_anonymous | Boolean | No | Whether to post anonymously (default: false) |
| is_published | Boolean | No | Whether to publish immediately (default: false) |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Create a new product comment
4response = requests.post('http://www.example.com/api/products/comments',
5 json={
6 'content': 'This product is amazing! Great quality and fast delivery.',
7 'user': 123,
8 'product': 456,
9 'rating': 5,
10 'is_published': True,
11 'is_anonymous': False
12 },
13 headers={'Authorization': 'Token <your_api_key>'}
14)
15print(response.json())
16
17# Create minimal comment
18response = requests.post('http://www.example.com/api/products/comments',
19 json={
20 'content': 'Good product overall.',
21 'user': 123,
22 'product': 456
23 },
24 headers={'Authorization': 'Token <your_api_key>'}
25)
26print(response.json())1# Create a new product comment
2curl -X POST "http://www.example.com/api/products/comments" \
3-H "Authorization: Token <your_api_key>" \
4-H "Content-Type: application/json" \
5-d '{
6 "content": "This product is amazing! Great quality and fast delivery.",
7 "user": 123,
8 "product": 456,
9 "rating": 5,
10 "is_published": true,
11 "is_anonymous": false
12}'
13
14# Create minimal comment
15curl -X POST "http://www.example.com/api/products/comments" \
16-H "Authorization: Token <your_api_key>" \
17-H "Content-Type: application/json" \
18-d '{
19 "content": "Good product overall.",
20 "user": 123,
21 "product": 456
22}'Status Codes
| Code | Description |
|---|---|
| 201 | Product comment created successfully |
| 400 | Bad request — invalid input |
| 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 require approval (is_published=true) to be visible to public users
- Anonymous comments hide user identification but retain moderation capabilities
- Comment content is limited to 500 characters maximum
- All timestamps are in ISO 8601 format (e.g., "2023-01-01T12:00:00Z")