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.
Parameter | Data Type | In | Description |
api_token | string | header | The API key of the customer account |
value | string | query | It searches attributes that include the value |
value__exact | string | query | It searches attributes that match the value exactly |
attribute | string | query | The 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.
Parameter | Data Type | Description |
attribute | id | The id of the attribute to which the attribute value is related |
value | string | Attribute's value |
label | string | Attribute's label. It is used on the back office frontend. |
order | int | Order |
erp_code | string | Attribute'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.
Parameter | Data Type | In | Description |
api_token | string | header | The API key of the customer account |
value | string | query | It searches attributes that include the value |
value__exact | string | query | It searches attributes that match the value exactly |
attribute | string | query | The ID of the attribute to which the attribute value is related |
label | string | query | It searches the attribute values that include the label |
erp_code | string | query | It 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.
Parameter | Data Type | Description |
attribute | id | The ID of the attribute to which the attribute value is related |
value | string | Attribute's value |
order | int | Attribute value’s order |
label | string | Attribute's label. It is used in the back-end front-end. |
erp_code | string | Attribute 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.
Parameter | Data Type | Description |
attribute | id | The ID of the attribute to which the attribute value is related |
value | string | Attribute's value |
order | int | Attribute value’s order |
order | string | Attribute's label. It is used on the back office front end. |
erp_code | string | Attribute 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.
Parameter | Data Type | In | Required | Description |
api_token | string | header | YES | The API key of the customer account |
attribute_key | id | body | How attributes are saved in DB. (Ex: color, size). | |
attribute | id | body | YES | The ID of attribute to which the attribute value is related |
value | string | body | YES | Attribute's value |
label | string | body | Attribute's label. It is used in the backend and frontend | |
order | int | body | Order | |
erp_code | string | body | YES | Attribute'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.
Parameter | Data Type | Description |
api_token | id | The ID of the attribute to which the attribute value is related |
value | string | Attribute's value |
label | string | Attribute's label. It is used in the backend and frontend |
order | int | Order |
erp_code | string | Attribute'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.
Parameter | Data Type | In | Description |
api_token | string | header | The API key of the customer account |
value | string | query | It searches attributes that include the value |
value__exact | string | query | It searches attributes that match the value exactly |
attribute | string | query | The 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/<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.
Parameter | Data Type | Description |
pk | id | The ID of the attribute value |
attribute | id | The ID of the attribute to which the attribute value is related |
value | string | Attribute's value |
label | string | Attribute's label. It is used on the back office frontend |
order | int | Order |
erp_code | string | Attribute 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"
}