Create Product Attribute
Creates a new attribute for a specific product.
HTTP Request
POST/api/products/:product_id/attributes
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| product_id | Integer | Yes | Unique ID of the product |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| attribute | Integer | Yes | Unique ID of the attribute to associate with the product |
| values | Array | Yes | Unique IDs of the attribute values to associate with the product |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3url = "http://www.example.com/api/products/123/attributes"
4headers = {
5 "Authorization": "Token <your_api_key>",
6 "Content-Type": "application/json"
7}
8data = {
9 "attribute": 1,
10 "values": [10, 11, 12]
11}
12response = requests.post(url, headers=headers, json=data)
13
14print(response.json())
15
16# Create product attribute with single value
17response = requests.post('http://www.example.com/api/products/123/attributes',
18 json={
19 'attribute': 2,
20 'values': [15]
21 },
22 headers={'Authorization': 'Token <your_api_key>'}
23)
24print(response.json())1# Create a new product attribute
2curl -X POST "http://www.example.com/api/products/123/attributes" \
3-H "Authorization: Token <your_api_key>" \
4-H "Content-Type: application/json" \
5-d '{
6 "attribute": 1,
7 "values": [10, 11, 12]
8}'
9
10# Create product attribute with single value
11curl -X POST "http://www.example.com/api/products/123/attributes" \
12-H "Authorization: Token <your_api_key>" \
13-H "Content-Type: application/json" \
14-d '{
15 "attribute": 2,
16 "values": [15]
17}'Status Codes
| Code | Description |
|---|---|
| 201 | Product attribute created successfully |
| 400 | Bad request — invalid input |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 404 | Not found — product or attribute does not exist |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the product attribute |
| attribute_data | Object | Details of the attribute (id, name, description) |
| value_data | Object | Details of the attribute value (id, value) |
| created_at | String (ISO 8601) | Timestamp when product attribute was created |
| updated_at | String (ISO 8601) | Timestamp when product attribute was last updated |
Attribute Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the attribute |
| name | String | Name of the attribute |
| description | String | Description of the attribute |
| created_at | String (ISO 8601) | Timestamp when attribute was created |
| updated_at | String (ISO 8601) | Timestamp when attribute was last updated |
Value Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the attribute value |
| value | String | The value of the attribute |
| created_at | String (ISO 8601) | Timestamp when attribute value was created |
| updated_at | String (ISO 8601) | Timestamp when attribute value was last updated |