Create Product Comment
Creates a new product comment.
HTTP Request
POST/api/products/comments/
NOTE: NOT USING THE TRAILING SLASH AT THE END OF THE URL RESULTS TO A 500 SERVER ERROR
Authorization
Authorization
- Required: Yes
- Permission: Staff with ProductCommentPermission or Admin
- Permission Code: 1881
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| rating | Integer | No | Rating given (1-5, default: 3) |
| content | String | Yes | Comment content (max 500 characters) |
| is_anonymous | Boolean | No | Whether to post anonymously (default: false) |
| is_published | Boolean | No | Whether to publish immediately (default: false) |
| user | Integer | Yes | User ID who is posting the comment |
| product | Integer | Yes | Product ID being commented on |
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}'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 |
| title | string | Title of the product |
Example Response
{
"id": 3,
"rating": 4,
"content": "consequatur",
"is_anonymous": true,
"is_published": false,
"created_at": "2025-12-24T13:53:04.595255Z",
"updated_at": "2025-12-24T13:53:04.595262Z",
"user_data": {
"id": 1,
"username": "BehroozGhorbani",
"full_name": "بهروز قربانی",
"avatar": "http://127.0.0.1:8000/media/users/avatars/photo22132188258.jpg"
},
"product_data": {
"id": 57,
"title": "لنت ترمز پیکان پژو"
},
"truncated_content": "consequatur"
}
Notes
- Rating scale: 1=Worst, 2=Bad, 3=Average, 4=Good, 5=Best