Skip to main content

Attribute

This article provides comprehensive information and documentation on a set of API methods specifically designed to handle product attributes. By leveraging these methods, users can retrieve, create, update, and search product attributes, 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 API.

Get Attributes

Attributes are features of the products. For example, a t-shirt has color, size, fabric, etc. as attributes; however, a mobile phone has camera resolution, screen brightness, memory and disk capacity, color etc. attributes.

You can query the attributes to get a list of defined attributes.

ParameterData TypeInDescription
api_tokenstringheaderThe API key of the customer account
limitintegerqueryAmount of line items per page that will be returned
pageintegerqueryPage number to return

Request GET

GET request is used for retrieving attributes. Check Search-Attribute section for filtering options.

content_type header represents the response type.

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

Accept-language header determines translatable fields responses.

Path: i1/attributes/


import requests
url = "https://{customer_api_url}/api/i1/attributes/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token),
'Accept-language':'en-us'
}

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

Response

Resource properties are in Python format. The table below shows attribute properties. Every field has been explained in the description section of the table.

ParameterData TypeDescription
keystringAttribute’s code
data_typeenumType of data the corresponding attribute contains. It could be text, email, text_area, date, datetime, boolean, valuelabel, dropdown, multiple, price, nested_object, image, file, model, bundle
valuestringAttribute's value
labelstringAttribute's label. It is used on the frontend
default_valuestringDefault value of the attribute
is_requiredbooleanDefines whether or not to leave this attribute blank when creating or updating the product
is_visiblebooleanDefines whether this attribute will appear on the backoffice panel
is_searchablebooleanDefines whether search can be made with this attribute
is_filterablebooleanDefines whether the value of this attribute can be filtered
is_variantbooleanDefines whether this attribute is variantable or not. For example, if this parameter is True for the "size" attribute, there will be a variant based on this value among child products linked to the parent product: X size t-shirt, L size t-shirt etc.
is_variant_listablebooleanDefines whether different variants of the same product will appear on the product listing page
namestringAttribute name
is_form_requiredbooleanCustomer must fill in a form when adding a product with "is form required == True" to the cart
is_form_field_requiredbooleanDefines whether the form field is required to fill
erp_codestringThe code of this attribute code in ERP
pre_attributebooleanDefines whether the attribute is used for pre products or products

“count” shows how many attributes exist in the system.

“next” shows the next cursor url to retrieve the desired attributes.

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

“results” shows every attribute detail with detailed field descriptions.

{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1457,
"key": "test_size_attribute2",
"data_type": {
"value": "dropdown",
"label": "dropdown",
},
"default_value": null,
"is_required": false,
"is_visible": false,
"is_searchable": false,
"is_filterable": false,
"is_variant": false,
"is_variant_listable": false,
"name": "test_size_attribute EN",
"is_form_required": false,
"is_form_field_required": false,
"erp_code": "erp_test_size_attribute_2",
"pre_attribute": false,
}
]
}

Request GET Instance

Retrieves an attribute with a unique identifier.

content_type header represents the response type.

Authorization header required header for authentication. You can retrieve api_token with login.

Accept-language header determines translatable fields responses.

Path: i1/attributes/<pk>/


import requests
url = "https://{customer_api_url}/api/i1/attributes/1457/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token),
'Accept-language':'en-us'
}

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

Response

Shows the details of the attribute with a given unique identifier.

{
"id": 1457,
"key": "test_size_attribute2",
"data_type": dropdown,
"default_value": null,
"is_required": false,
"is_visible": false,
"is_searchable": false,
"is_filterable": false,
"is_variant": false,
"is_variant_listable": false,
"name": "test_size_attribute EN",
"is_form_required": false,
"is_form_field_required": false,
"erp_code": "erp_test_size_attribute_2",
"pre_attribute": false,
}

Search Attribute

GET requests can be filtered with parameters. You can search "attribute" according to these labels. All the below labels are acceptable as query parameters. For example, if you are looking for only required attributes, you need to send ‘?is_required=True’ at the end of the url.

ParameterData TypeInDescription
api_tokenstringheaderThe API key of the customer account
limitintegerqueryAmount of line items per page that will be returned
pageintegerqueryPage number to return
namestringparamsAttribute name
keystringparamsAttribute code
is_variantbooleanparamsTrue / False
is_searchablebooleanparamsTrue / False
is_visiblebooleanparamsTrue / False
is_requiredbooleanparamsTrue / False
data_typebooleanparamstext, text_area, dropdown
is_localizablebooleanparamsTrue / False
is_variant_listablebooleanparamsTrue / False
modified_date__gtdatetimeparamsLast updated date greater than
modified_date__ltdatetimeparamsLast updated date lower than
modified_date__gtedatetimeparamsLast updated date greater and equal than
modified_date__ltedatetimeparamsLast updated date lower and equal than
modified_date__date__gtdateparamsLast updated date greater than
modified_date__date__ltdateparamsLast updated date lower than
modified_date__date__gtedateparamsLast updated date greater and equal than
modified_date__date__ltedateparamsLast updated date lower and equal than
accept-languagestringparamsLanguage code (Ex: "en-us","tr-tr")

Request GET

Retrieves attributes with filtered desired values. Below example shows filtering attributes with ‘attribute_name’.

‘content_type’ header represents the response type.

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

‘Accept-language’ header determines translatable fields responses.

Path: attributes/


import requests

url = "https://{customer_api_url}/api/i1/attributes/?<attribute_name>=<attribute_value>"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"

headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token),
'Accept-language':'en-us'
}
params = {
'key':'test_text_attribute',
'limit':'4',
'page':'1'
}

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

Response

Response contains all attribute data with search parameters and with pagination. Response status is expected to be HTTP-200 Successful.

The table below shows attribute properties. Every field has been explained in the description section of the table.

Resource properties are in Python format.

ParameterData TypeDescription
IDintegerAttribute identifier number
keystringAttribute code
data_typeenumSpecifies the data type of the property. It can take the following values: text, text_area, dropdown
valuestringAttribute's value
labelstringAttribute's label. It is used on the frontend
default_valuestringDefault value of the attribute
is_requiredbooleanDefines whether or not to leave this attribute blank when creating or updating the product
is_visiblebooleanDefines whether this attribute will appear on the back office panel
is_searchablebooleanDefines whether search can be made with this attribute
is_filterablebooleanDefines whether the value of this attribute can be filtered
is_variantbooleanDefines whether this attribute is variantable or not. For example, if this parameter is True for the "size" attribute, there will be a variant based on this value among child products linked to the parent product: X size t-shirt, L size t-shirt etc.
is_variant_listablebooleanDefines whether different variants of the same product will appear on the product listing page
namestringAttribute name
is_form_requiredbooleanCustomer must fill in a form when adding a product with "is form required == True" to the cart
is_form_field_requiredbooleanDefines whether the form field is required to fill
erp_codestringThe code of this attribute code in ERP

“count” shows how many attributes exist in the system.

“next” shows the next page url to retrieve the desired attribute.

“previous” shows the previous page url to retrieve the desired attribute.

“results” shows every attribute property with detailed field descriptions.


{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1458,
"key": "test_text_attribute",
"data_type": {
"value": "text",
"label": "Text"
},
"default_value": null,
"is_required": false,
"is_visible": false,
"is_searchable": false,
"is_filterable": false,
"is_variant": false,
"is_variant_listable": false,
"name": "Dummy Size",
"is_form_required": false,
"is_form_field_required": false,
"erp_code": "erp_test_text_attribute",
"pre_attribute": false
}
]
}

Create Attribute

Attributes are features of the products. For example, a t-shirt has color, size, fabric, etc. as attributes; however, a mobile phone has camera resolution, screen brightness, memory and disk capacity, color etc. attributes.

You can query the attributes to get a list of defined attributes.

ParameterData TypeInRequiredDescription
api_token string header YES The API key of the customer account
default_value string body The default value for the attribute. For example the default value for the size attribute is M.
is_visible boolean body (default True) Determines whether the attribute will appear on the website. "_False could be selected for attributes that will be used during the back office (Omnitron) and not used on the website. For example, ERP color code, ERP SKU, etc.
data_type string body YES Specifies the data type of the property. It can take the following values: text, text_area, dropdown
translations list body If the attribute has different language support, the names of the attribute used in different languages are listed under **translations**. Such as, "en-us": "name": "SIZE"
description string body Description of the attribute
is_form_required boolean body (default False) The customer needs to fill out a form when adding a product whose is_form_required value is True to the cart. Such as the name and note to be written on the jewelry, watches, wallets, flowers.
is_form_field_required boolean body (default False) Defines whether the fields in the form (associated with "is_form_required") shown to the customer are required.
is_filterable boolean body (default False) If the parameter is True, this attribute can be viewed in filters.
is_searchable boolean body (default True) If the parameter is True, the customer can search with the value of the attribute on the website.
pre_attribute boolean body (default False) The pre_attribute value True should be defined if the attributes integrated from the ERP are requested to be reviewed and approved before they are put into use.
is_localizable boolean body (default False) If the value of the attribute will be used in different languages, True must be entered. For example, if this value is True, the description attribute can be used like EN: This rug is made of polyester from recycled PET bottles, and NL: Dit vloerkleed is gemaakt van polyester van gerecyclede PET-flessen.
key string body YES Unique attribute code
erp_code string body YES The attribute code included on ERP
is_variant boolean body (default 'False') Defines whether the product can be variant or not via the attribute. For example, if is_variant is 'True'for the size attribute, it is possible to make variants such as X size sweater, L size sweater among child products connected to the same parent product.
is_variant_listable boolean body (default False) Determines whether different variants of the same product will appear on the product listing page.
is_required boolean body (default False) Defines whether the attribute is required. It determines whether the attribute value can be left blank when creating or updating the product.
name string body YES Attribute name

Request POST

In this example, the attribute will be created with a dropdown type and in Turkish ("tr-tr") which is Omnitron's default language.

Path: v1/attributes/


import requests
import json

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

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

data = {
"key": "test_size_attribute2",
"data_type": "dropdown",
"default_value": None,
"is_required": False,
"is_visible": False,
"is_searchable": False,
"is_filterable": False,
"is_variant": False,
"is_variant_listable": False,
"name": "test_size_attribute",
"is_form_required": False,
"is_form_field_required": False,
"erp_code": "erp_test_size_attribute_2",
"pre_attribute": False,
"description": None
}

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

Response

Shows the details of the attribute that was created.


{
"pk": 1457,
"key": "test_size_attribute2",
"data_type": "dropdown",
"default_value": null,
"is_required": false,
"is_visible": false,
"is_searchable": false,
"is_filterable": false,
"is_variant": false,
"is_variant_listable": false,
"name": "test_size_attribute",
"is_form_required": false,
"is_form_field_required": false,
"erp_code": "erp_test_size_attribute_2",
"pre_attribute": false,
"description": null,
"is_localizable": false
}

Language Support

Note: If Attribute type is ‘text’ or ‘textarea’ and the attribute will be used in different languages, is_localizable parameter should be _True. In order to send language translation for an attribute, the Accept-Language parameter needs to be added to the header. Accept-Language parameter is an optional parameter. If it is not sent, Omnitron's default language will be defined.

Request POST

In this example, the attribute will be created with text type and in Turkish ("tr-tr") which is Omnitron's default language.

Path: v1/attributes/


import requests
import json

url = "https://{customer_api_url}/api/v1/products/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"

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

data = {
"key": "test_text_attribute",
"data_type": "text",
"default_value": None,
"is_localizable": True,
"is_required": False,
"is_visible": False,
"is_searchable": False,
"is_filterable": False,
"is_variant": False,
"is_variant_listable": False,
"name": "Dummy Size",
"is_form_required": False,
"is_form_field_required": False,
"erp_code": "erp_test_text_attribute",
"pre_attribute": False,
"description": None
}

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

Response

Returns the created attribute data. Response status is expected to be HTTP-201 Created. “modified_date” and “created_date” parameters show the date when the attribute was last modified, and the date when it was created.


{
"pk": 1458,
"key": "test_text_attribute",
"data_type": "text",
"default_value": null,
"is_required": false,
"is_visible": false,
"is_searchable": false,
"is_filterable": false,
"is_variant": false,
"is_variant_listable": false,
"name": "Dummy Size",
"is_form_required": false,
"is_form_field_required": false,
"erp_code": "erp_test_text_attribute",
"pre_attribute": false,
"description": null,
"is_localizable": true
"modified_date": "2016-12-14T14:56:02.160001Z",
"created_date": "2016-12-14T14:56:02.160001Z",
}

Bad Request Responses

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

“islocalizable” property can be _True only if ‘data_type’ of an attribute is ‘text’ or ‘text_area’.


{
"non_field_errors": [
"is_localizable field cannot be True when Attribute data_type is not one of text or text area"]
}

“erp_code” is a unique field and doesn’t accept duplicate data.


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

There are some reserved keys which cannot be used to create attributes. Reserved keys are Product model fields excluding description, brand, weight and tax_rate. Check the Product section to see the entire reserved key list.


{
"non_field_errors": "Requested key name cannot be used. modified_date is reserved.",
"error_code": "attribute_200_6"
}

Update Attribute

To update an attribute, it is necessary to know its ID. For example, you change the ‘isvisible’ parameter from _False to True. There are some restrictions with which you cannot perform an update. How to get ID and other details are explained under Search Attribute section.

ParameterData TypeInDescription
api_tokenstringheaderThe API key of the customer account
default_valuestringbodyThe default value for the attribute. For example, the default value for the size attribute is M.
is_visiblebooleanbody(default 'True') Determines whether the feature will appear on the website. 'False' could be selected for attributes that will be used at the back office (Omnitron) and not used on the website. For example, ERP color code, ERP SKU, etc.
data_typestringbodySpecifies the data type of the property. It can take the following values: text, text_area, dropdown
translationslistbodyIf the attribute has different language support, the names of the attribute used in different languages are listed under translations. For example, `"en-us": "name": "SIZE"` .
descriptionstingbodyDescription of attribute
is_form_requiredbooleanbody(default 'False') The customer needs to fill out a form when adding a product whose is_form_required value is 'True' to the cart. Such as the name and note to be written on the jewelry, watches, wallets, flowers.
is_form_field_requiredbooleanbody(default 'False') Defines whether the fields in the form (associated with "is_form_required") shown to the customer are required.
is_filterablebooleanbody(default 'False') If the parameter is 'True', this attribute can be viewed in filters
is_searchablebooleanbody(default 'True') If the parameter is 'True', the customer can search with the value of the attribute on the website
pre_attributebooleanbody(default 'False') The pre_attribute value 'True' should be defined if the attributes integrated from the ERP are requested to be reviewed and approved before they are put into use
is_localizablebooleanbody(default 'False') If the value of the attribute will be used in different languages, 'True' must be entered. For example, if this value is 'True', the description attribute can be used as EN: This rug is made of polyester from recycled PET bottles, and NL: Dit vloerkleed is gemaakt van polyester van gerecyclede PET-flessen.
keystingbodyUnique attribute code
erp_codestringbodyThe attribute code included on ERP
is_variantbooleanbody(default 'False') Defines whether the product can be variant or not via the attribute. For example, if is_variant is 'True' for the size attribute, it is possible to make variants such as X size sweater, L size sweater among child products connected to the same parent product.
is_variant_listablebooleanbody(default 'False') Determines whether different variants of the same product will appear on the product listing page
is_requiredbooleanbody(default 'False') Defines whether the attribute is required. It determines whether the attribute value can be left blank when creating or updating the product.
namestringbodyAttribute name
is_localizablebooleanbody(default 'False') Defines whether the attribute is translatable or not. Only ‘text’ or ‘text_area’ type of attributes can be localizable

Request PATCH

There are three sections of an update request. Url with instance ID, headers and data which can change the desired field(s) of an attribute.

‘content_type’ header represents the response type.

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

Path: v1/attributes/<ATTRIBUTE_ID>


import requests
import json

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


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

cookies = {
'django_language':'en-us'
}

data = {
"key": "test_size_attribute2",
"data_type": "dropdown",
"name": "test_size_attribute EN"
}

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

Response

After the update is done, the response shows the updated data of the attribute.

‘created_date’ shows the date when the attribute was created.

‘modified_date’ shows the date of the last attribute update.


{
"pk": 1457,
"key": "test_size_attribute2",
"data_type": "dropdown",
"default_value": null,
"is_required": false,
"is_visible": false,
"is_searchable": false,
"is_filterable": false,
"is_variant": false,
"is_variant_listable": false,
"name": "test_size_attribute EN",
"is_form_required": false,
"is_form_field_required": false,
"erp_code": "erp_test_size_attribute_2",
"pre_attribute": false,
"description": null,
"modified_date": "2022-02-21T08:13:40.424413Z",
"created_date": "2016-12-14T14:56:02.160001Z,
"is_localizable: false
}

Bad Request Responses

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


{
"non_field_errors": "Data type can not be updated",
"error_code": "attribute_200_5"
}

If the ‘islocalizable’ field is _True, any Product has the attribute. ‘Islozalizable’ field cannot be updated to _False.


{
"non_field_errors": "Attribute is used by Product(s). Can not update is_localizable field!",
"error_code": "attribute_200_4"
}

If an attribute is used by any Product, the key field cannot be updated.


{
"non_field_errors": "Attribute is used by Product(s). Can not update attribute_key field!",
"error_code": "attribute_200_4"
}

There are some reserved keys which cannot be used to create attributes. Reserved keys are Product model fields excluding description, brand, weight and tax_rate. Check the Product section to see the entire reserved key list.


{
"non_field_errors": "Requested key name cannot be used. modified_date is reserved.",
"error_code": "attribute_200_6"
}