Skip to main content

Attribute Value

This article provides comprehensive information and documentation on a set of API methods specifically designed to handle product attribute values. By leveraging these methods, users can retrieve, create, update, and search product attribute values, allowing for seamless integration and management of product data within the system.

The article includes detailed explanations, parameter descriptions, and usage examples for each API method, empowering developers to effectively utilize the capabilities provided by the product attribute value API.

Get Attribute Values

To get attribute values from the system, you can send the GET request. To filter, you can add parameters such as value, value_exact, attribute as in QueryString. If you don't add parameters for the filter, all attribute values in the system will be returned.

ParameterData TypeInDescription
api_tokenstringheaderThe API key of the customer account
valuestringqueryIt searches attributes that include the value
value__exactstringqueryIt searches attributes that match the value exactly
attributestringqueryThe ID of the attribute to which the attribute value is related

Request GET

GET request is used for retrieving current attribute values from the system. This request is expected to return all attribute value data according to page and limit parameters.

‘content_type’ header represents the response type.

‘Authorization’ header is a required header for authentication. You can retrieve api_token with login.

‘limit’ determines how many attribute values are shown in the page. Default value is 10.

‘page’ determines the page of the retrieved results. Default value is 1.

Path:attribute_value/


import requests

url = "https://{customer_api_url}/api/i1/attribute_value/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"

headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
params = {
'limit': 4,
'page': 2
}

response = requests.get(url, headers=headers , params=params)
print(response.text)

Response

Response contains all attribute value data with given parameters. Response status is expected to be HTTP-200 Successful.

Resource properties are in Python format.

ParameterData TypeDescription
attributeidThe id of the attribute to which the attribute value is related
valuestringAttribute's value
labelstringAttribute's label. It is used on the back office frontend.
orderintOrder
erp_codestringAttribute's value code in ERP

“count” shows how many attribute values exist in the system.

“next” shows the next cursor url to retrieve the desired attribute values.

“previous” shows the previous cursor url to retrieve the desired attribute values.

“results” shows every attribute value detail.


{
"count": 498,
"next": "https://{customer_api_url}/api/i1/attribute_value/attribute_value/?limit=4&page=2",
"previous": null,
"results": [
{
"pk": 3672,
"attribute": 158,
"value": "40/41",
"order": null,
"label": null,
"erp_code": "40/41",
},
{
"pk": 3673,
"attribute": 158,
"value": "26-30",
"order": null,
"label": null,
"erp_code": "26-30",
},
{
"pk": 3674,
"attribute": 158,
"value": "26-32",
"order": null,
"label": null,
"erp_code": "26-32",
},
{
"pk": 3675,
"attribute": 158,
"value": "36/37",
"order": null,
"label": null,
"erp_code": "36/37",
}
]
}

Search Attribute Value

Filter attribute values in the system with allowed fields using a GET request. The table below shows the filtering options with details. If a user doesn’t add any filtering options in the query, all of the attribute values will be returned in the system.

ParameterData TypeInDescription
api_tokenstringheaderThe API key of the customer account
valuestringqueryIt searches attributes that include the value
value__exactstringqueryIt searches attributes that match the value exactly
attributestringqueryThe ID of the attribute to which the attribute value is related
labelstringqueryIt searches the attribute values that include the label
erp_codestringqueryIt searches the attribute values that include the erp_code

Request GET

‘content_type’ header represents the response type.

‘Authorization’ header is a required header for authentication. You can retrieve api_token with login.

‘django_language’ cookies allow you to retrieve desired language values. ‘Attribute Value’ field is a translatable field. If there are no translations with the given language code, the response shows the default language value.

The sample request below filters all attribute values related to the attributes with ID 205.

Path:<code>i1/attribute_value/</code></strong>


import requests

url = "https://{customer_api_url}/api/i1/attribute_value/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"

headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
cookies = {
'django_language':'en-us' # searches values in English
}

params = {
'attribute': '205' #attribute id
}

response = requests.get(url, headers=headers, cookies=cookies, params=params)
print(response.text)

Response

Response contains all attribute value data with search parameters. Response status is expected to be HTTP-200 Successful. Resource properties are in Python format.

ParameterData TypeDescription
attributeidThe ID of the attribute to which the attribute value is related
valuestringAttribute's value
orderintAttribute value’s order
labelstringAttribute's label. It is used in the back-end front-end.
erp_codestringAttribute value’s code in ERP

“count” shows how many attribute values exist in the system with used filter options.

“next” shows the next cursor url to retrieve the desired attribute values.

“previous” shows the previous cursor url to retrieve the desired attribute values.

“results” shows every attribute value detail.

{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"pk": 5214,
"attribute": 205,
"value": "2051",
"order": 1,
"label": "dark green ",
"erp_code": "erp-2051",
}
]
}

Request GET

Below request is for retrieving Turkish values of the attribute values. Language is controlled by the ‘django_language’ cookie or ‘Accept-Language’ header. If the attribute value does not have translations for the given language code, it returns the default value.

Path: v1/attribute_value/


import requests
url = "https://{customer_api_url}/api/i1/attribute_value/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
cookies = {
'django_language':'tr-tr' # searches values in Turkish
}
params = {
'attribute': '205' #attribute id
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)
print(response.text)

Response

Response contains all attribute value data with search parameters. Response status is expected to be HTTP-200 Successful. Resource properties are in Python format.

ParameterData TypeDescription
attributeidThe ID of the attribute to which the attribute value is related
valuestringAttribute's value
orderintAttribute value’s order
orderstringAttribute's label. It is used on the back office front end.
erp_codestringAttribute value’s code in ERP

“count” shows how many attribute values exist in the system with used filter options.

“next” shows the next cursor url to retrieve the desired attribute values.

“previous” shows the previous cursor url to retrieve the desired attribute values.

“results” shows every attribute value detail.


{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"pk": 5214,
"attribute": 205,
"value": "2051",
"order": 1,
"label": "koyu yesil",
"erp_code": "erp-2051",
}
]
}

Create Attribute Value

Attribute value must be attached to an attribute. For this reason, attribute ID also must be sent when creating an attribute value. How to get attribute ID and other details are explained under Search Attribute section.

ParameterData TypeInRequiredDescription
api_tokenstringheaderYESThe API key of the customer account
attribute_keyidbodyHow attributes are saved in DB. (Ex: color, size).
attributeidbodyYESThe ID of attribute to which the attribute value is related
valuestringbodyYESAttribute's value
labelstringbodyAttribute's label. It is used in the backend and frontend
orderintbodyOrder
erp_codestringbodyYESAttribute's value code in ERP

Request POST

POST request is needed for creating a new attribute value.

‘content_type’ header represents the response type.

‘Authorization’ header is a required header for authentication. You can retrieve api_token with login.

The ‘Translation’ key is used to add different language translations for the attribute value.

Path: v1/attribute_value/


import requests
url = "https://{customer_api_url}/api/i1/attribute_value/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
cookies = {
'django_language':'en-us' #default Omnitron language
}
data = {
'attribute' : '160',
'label': 'dark green', # in default language
'translations': {
'de-de':{
'label':'dunkelgrün' # in German
},
},
'value': '1606',
'erp_code': 'erp-1606',
'order': 1
}
response = requests.post(url, headers=headers, cookies=cookies , data=json.dumps(data))
print(response.text)


Response

Returns the created attribute value data. Response status is expected to be HTTP-201 Created. Resource Properties are in Python format.

The table below shows the field details of the created attribute value.

ParameterData TypeDescription
api_tokenidThe ID of the attribute to which the attribute value is related
valuestringAttribute's value
labelstringAttribute's label. It is used in the backend and frontend
orderintOrder
erp_codestringAttribute's value code in ERP

{
"pk": 5211,
"attribute": 160,
"value": "1606",
"order": 1,
"label": "dark green",
"erp_code": "erp-1606",
}

Bad Request Responses

When the requested action cannot be executed, API gives an explanation about the request.

“Erp_code” and “value” are unique fields and don’t accept duplicate data.


{
"non_field_errors": "(erp_code:erp_color) is already exists",
"error_code": "attribute__value_201_1"
}

{
"non_field_errors": "(value:value) is already exists",
"error_code": "attribute__value_201_1"
}

Update Attribute Value

To update the value of the attribute, it is necessary to know the ID of the attribute value. How to get ID and other details are explained under Search Attribute Value section.

ParameterData TypeInDescription
api_tokenstringheaderThe API key of the customer account
valuestringqueryIt searches attributes that include the value
value__exactstringqueryIt searches attributes that match the value exactly
attributestringqueryThe ID of the attribute to which the attribute value is related

Request PATCH

Request sample to update an attribute value. Attribute Value ID is required to perform this action. If the given ID is not found in the system, the response code is: 404 Not Found.

‘content_type’ header represents the response type.

‘Authorization’ header is a required header for authentication. You can retrieve api_token with login.

Path:/api/i1/attribute_value/&lt;ATTRIBUTE_VALUE_ID>/


import requests

url = "https://{customer_api_url}/api/i1/attribute_value/5214/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"

headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}

cookies = {
'django_language':'tr-tr'
}

data = {
'label':'koyu yesil',
'translations': {
'en-us':{
'label':'dark green'
}
},
}

response = requests.patch(url, headers=headers, cookies=cookies , data=json.dumps(data))
print(response.text)

Response

Returns the updated version of the attribute value fields. Resource Properties are in Python format.

ParameterData TypeDescription
pkidThe ID of the attribute value
attributeidThe ID of the attribute to which the attribute value is related
valuestringAttribute's value
labelstringAttribute's label. It is used on the back office frontend
orderintOrder
erp_codestringAttribute value’s code in ERP

{
"pk": 5214,
"attribute": 205,
"value": "2051",
"order": 1,
"label": "koyu yesil",
"erp_code": "erp-2051",
}

Bad Request Responses

When the requested action cannot be performed, API gives an explanation about the request.

“erp_code” is a unique field and does not accept duplicate data.


{
"non_field_errors": "(erp_code:erp_color) is already exists",
"error_code": "attribute__value_201_1"
}

“value” is a unique field.


{
"non_field_errors": "(value:value) is already exists",
"error_code": "attribute__value_201_1"
}

If any product is using the “attribute_value”, the value of it cannot be updated.


{
"non_field_errors": "AttributeValue can not be updated",
"error_code": "attribute__value_201_2"
}