Skip to main content

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

ParameterTypeRequiredDescription
product_idIntegerYesUnique ID of the product

Request Body

FieldTypeRequiredDescription
attributeIntegerYesUnique ID of the attribute to associate with the product
valuesArrayYesUnique IDs of the attribute values to associate with the product

Example Requests

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

Status Codes

CodeDescription
201Product attribute created successfully
400Bad request — invalid input
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404Not found — product or attribute does not exist
500Internal server error

Response Fields

FieldTypeDescription
idIntegerUnique ID of the product attribute
attribute_dataObjectDetails of the attribute (id, name, description)
value_dataObjectDetails of the attribute value (id, value)
created_atString (ISO 8601)Timestamp when product attribute was created
updated_atString (ISO 8601)Timestamp when product attribute was last updated

Attribute Data Structure

FieldTypeDescription
idIntegerUnique ID of the attribute
nameStringName of the attribute
descriptionStringDescription of the attribute
created_atString (ISO 8601)Timestamp when attribute was created
updated_atString (ISO 8601)Timestamp when attribute was last updated

Value Data Structure

FieldTypeDescription
idIntegerUnique ID of the attribute value
valueStringThe value of the attribute
created_atString (ISO 8601)Timestamp when attribute value was created
updated_atString (ISO 8601)Timestamp when attribute value was last updated