1import requests
2
3# Create a new comment
4response = requests.post('http://www.example.com/api/shop/products/iphone-14-pro/comments',
5 json={
6 'rating': 5,
7 'content': 'Excellent product! Really happy with the purchase.',
8 'is_anonymous': False
9 },
10 headers={'Authorization': 'Token <your_api_key>'}
11)
12print(response.json())
13
14# Create anonymous comment
15response = requests.post('http://www.example.com/api/shop/products/iphone-14-pro/comments',
16 json={
17 'rating': 4,
18 'content': 'Good value for money.',
19 'is_anonymous': True
20 },
21 headers={'Authorization': 'Token <your_api_key>'}
22)
23print(response.json())
1# Create a new comment
2curl -X POST "http://www.example.com/api/shop/products/iphone-14-pro/comments" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
3 "rating": 5,
4 "content": "Excellent product! Really happy with the purchase.",
5 "is_anonymous": false
6}'
7
8# Create anonymous comment
9curl -X POST "http://www.example.com/api/shop/products/iphone-14-pro/comments" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
10 "rating": 4,
11 "content": "Good value for money.",
12 "is_anonymous": true
13}'