Skip to main content

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

FieldTypeRequiredDescription
ratingIntegerNoRating given (1-5, default: 3)
contentStringYesComment content (max 500 characters)
is_anonymousBooleanNoWhether to post anonymously (default: false)
is_publishedBooleanNoWhether to publish immediately (default: false)
userIntegerYesUser ID who is posting the comment
productIntegerYesProduct ID being commented on

Example Requests

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())

Response Fields

FieldTypeDescription
idintegerUnique ID of the comment
ratingintegerRating given (1-5: Worst, Bad, Average, Good, Best)
contentstringComment content (max 500 characters)
is_anonymousbooleanWhether the comment is posted anonymously
is_publishedbooleanWhether the comment is published
user_dataobjectUser details (read-only)
product_dataobjectProduct details (read-only)
truncated_contentstringShortened version of content
created_atstring (ISO 8601)Timestamp when comment was created
updated_atstring (ISO 8601)Timestamp when comment was last updated

User Data Structure

FieldTypeDescription
idintegerUnique ID of the user
usernamestringUsername of the user
full_namestringFull name of the user
avatarstringURL of the user avatar image

Product Data Structure

FieldTypeDescription
idintegerUnique ID of the product
titlestringTitle 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