Skip to main content

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

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

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

Status Codes

CodeDescription
201Product comment created successfully
400Bad request — invalid input
401Unauthorized — authentication required
403Forbidden — insufficient permissions
500Internal server error

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
namestringName 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")