# Attributes & Sets

The following four items will be discussed within the scope of product attributes.

1. Attribute
2. AttributeSet
3. AttributeConfig
4. AttributeValue

During the initial installation of Omnitron, product attributes, namely Attribute values, are created before the products themselves. AttributeSet values are created to keep these attribute values together. AttributeConfigs are then added to link Attributes and AttributeSets. Attributes and AttributeSets are linked completely through AttributeConfig, as there is no direct relation between them. Finally, an AttributeValue is added for each Attribute.

#### 1. Attribute

Indicates product attributes. Product properties, such as size, color, etc. are called Attributes. Attributes `AttributeInputTypes {omnicore.products.enums.AttributeInputTypes}` can have the following types: `text`, `boolean`, `dropdown` etc. Attribute values of products not productized are controlled with the `pre_attribute: bool` value, while the attribute values of a product marked as `pre_product will be pre_attibute=True`. Attribute objects are multilingual and can be localized.

#### 2. AttributeSet

Multiple Attributes form an `AttributeSet`. For example, the size and color of a product created for clothing will be the AttributeSet collectively belonging to the clothing products. AttributeSet may be of two different types: simple and grouped, as specified in `AttributeSetType {omnicore.products.enums.AttributeSetTypes}`.

#### 3. AttributeConfig

AttributeConfig is a bridge between Attribute and AttributeSet, and singular between the two properties. It means that there can only be one AttributeConfig between Attribute and AttributeSet.

#### 4. AttributeValue

Values of the product’s attributes. If a garment size is Attribute, sizes such as X, M, L and XL are AttributeValue. AttributeValue objects are multilingual and can be localized.

## `GET` Attributes

Path: `/api/v1/attributes/`

Brings the attribute values from the Attribute table. Gets the filter parameters with `{omnitron.products.resources.filters.AttributeFilter}` in AttributeFilter as query parameters. Supports pagination with ViewSet’s inheritance from `ListModelMixin` with query parameters of `page=X` and `limit=Y`.

**AttributeFilter**

Used in listing operations with GET used in AttributeViewSet. It can get the following parameters as a filter.

* data\_type: Contains Attribute type, takes AttributeInputTypes enum values. It allows multiple selections. E.g: /?data\_type=X\&data\_type=Y
* key: The code for the Attribute, requires an exact match.
* name:The namespace for the Attribute. It only needs to contain this value and works as case-sensitive.
* is\_required: Takes True/False value.
* is\_searchable: Takes True/False value.
* is\_variant: Takes True/False value.
* is\_variant\_listable: Takes True/False value.
* is\_visible: Takes True/False value.

## Attribute API Methods

### `GET` Attributes by Attribute Data Type

Path: `api/v1/attributes/?data_type=text/`

```json
{
  "count": 52,
  "next": "https://{customer_omnitron_url}/api/v1/attributes/?data_type=text&limit=20&page=2",
  "previous": null,
  "results": [
    {
      "pk": 995,
      "key": "max_installment",
      "data_type": "text",
      "default_value": null,
      "is_required": false,
      "is_visible": true,
      "is_searchable": false,
      "is_filterable": false,
      "is_variant": false,
      "is_variant_listable": false,
      "name": "max_installment",
      "is_form_required": false,
      "is_form_field_required": false,
      "erp_code": "max_installment",
      "pre_attribute": false,
      "description": "max_installment",
      "is_localizable": false,
      "entity_type": 1
      "modified_date": "2022-11-24T08:53:33.341501Z",
      "created_date": "2021-02-23T08:44:48.034000Z",

    }
  ]
}
```

### `POST` Create Attribute

Path: `api/v1/attributes/`

Adds a new record to the Attribute table. It is validated with AttributeSerializer. If the data is not suitable, it returns HTTP400. If there is an error or non-compliance in the service layer during the recording process, it returns HTTP406.

```json
{
    "key": "test",
    "data_type": "dropdown",
    "is_required": false,
    "is_visible": true,
    "is_searchable": false,
    "is_filterable": false,
    "is_variant": false,
    "is_variant_listable": false,
    "name": "Test Dropdown",
    "is_form_required": false,
    "is_form_field_required": false,
    "erp_code": "erp_test",
    "pre_attribute": false,
    "is_localizable": false
}
```

**Response**

```json
{
    "pk": 1325,
    "key": "test",
    "data_type": "dropdown",
    "default_value": null,
    "is_required": false,
    "is_visible": true,
    "is_searchable": false,
    "is_filterable": false,
    "is_variant": false,
    "is_variant_listable": false,
    "name": "Test Dropdown",
    "is_form_required": false,
    "is_form_field_required": false,
    "erp_code": "erp_test",
    "pre_attribute": false,
    "description": null,
    "is_localizable": false,
    "modified_date": "2023-01-04T19:21:28.149803Z",
    "created_date": "2023-01-04T19:21:28.149784Z",
    "entity_type": 1
}
```

**Errors**

```json
{
    "key": [
        "attribute with this key already exists."
    ]
}
-- OR
{
    "non_field_errors": "(erp_code:erp_gender) already exists",
    "error_code": "attribute_200_1"
}
```

### `DELETE` Attribute

Path: `/api/v1/attributes/{pk}/`

Deletes the object of the relevant primary key from the Attribute table. If it cannot find the object, it returns HTTP404.

**Response**

HTTP204

### `GET` Attribute

Path: `/api/v1/attributes/{pk}/`

Gets the object of the relevant primary key from the Attribute table. If it cannot find the object, it returns HTTP404.

**Response**

```json
{
    "pk": 995,
    "key": "max_installment",
    "data_type": "text",
    "default_value": null,
    "is_required": false,
    "is_visible": true,
    "is_searchable": false,
    "is_filterable": false,
    "is_variant": false,
    "is_variant_listable": false,
    "name": "max_installment",
    "is_form_required": false,
    "is_form_field_required": false,
    "erp_code": "max_installment",
    "pre_attribute": false,
    "description": "max_installment",
    "is_localizable": false
}
```

### `PATCH` Update Attribute

Path: `/api/v1/attributes/{pk}/`

Partially updates the object of the relevant primary key from the Attribute table. It is validated with AttributeSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With a partial update behavior, it only updates the sent parameters.

**Body**

```json
{
    "name": "Test Dropdown 1"
}
```

**Response**

```json
{
    "pk": 63,
    "key": "test",
    "data_type": "dropdown",
    "default_value": null,
    "is_required": false,
    "is_visible": true,
    "is_searchable": false,
    "is_filterable": false,
    "is_variant": false,
    "is_variant_listable": false,
    "name": "Test Dropdown 1",
    "is_form_required": false,
    "is_form_field_required": false,
    "erp_code": "test",
    "pre_attribute": false,
    "description": null,
    "modified_date": "2023-01-04T19:24:56.538441Z",
    "created_date": "2023-01-04T19:21:28.149784Z",
    "entity_type": 1,
    "is_localizable": false
}
```

**Errors**

```json
{
    "key": [
        "You can only use lowercase and uppercase letters in English alphabet, digits and underscores."
    ]
}
-- OR
{
    "data_type": [
        "No matching type."
    ]
}
-- OR
{
    "non_field_errors": "Data Type can not be updated.",
    "error_code": "attribute_200_5"
}
-- OR
{
    "non_field_errors": [
        "is_localizable field cannot be True when Attribute data_type is not one of text or text_area."
    ]
}
```

### `PUT` Update Attribute

Path: `/api/v1/attributes/{pk}/`

Updates the object of the relevant primary key from the Attribute table. It is validated with AttributeSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With an update behavior, it updates the entire object.

### `GET` Attributes Details

Path: `/api/v1/attributes/detailed/`

Exhibits the same behavior as Attribute listing, but the return parameters are more detailed. The data\_type and visible\_values fields are retrieved in detail.

**Response**

```json
{
  "count": 52,
  "next": "https://{customer_omnitron_url}/api/v1/attributes/detailed/?page=2",
  "previous": null,
  "results": [
    {
      "pk": 995,
      "key": "max_installment",
      "data_type": {
        "value": "text",
        "label": "Text"
      },
      "default_value": null,
      "is_required": false,
      "is_visible": true,
      "is_searchable": false,
      "is_filterable": false,
      "is_variant": false,
      "is_variant_listable": false,
      "name": "max_installment",
      "is_form_required": false,
      "is_form_field_required": false,
      "erp_code": "max_installment",
      "pre_attribute": false,
      "description": "max_installment",            
      "modified_date": "2017-01-21T14:54:14.364000Z",
      "created_date": "2016-12-14T15:01:20.124000Z",
      "entity_type": 1,
      "visible_values": []
    }
  ]
}
```

### `GET` Attribute Detail

Path: `/api/v1/attributes/{pk}/detailed/`

Exhibits the same behavior as getting Attributes, but the return parameters are more detailed. The data\_type and visible\_values fields are retrieved in detail.

**Response**

```json
{
  "pk": 269,
  "key": "forbidden",
  "data_type": {
    "value": "bool",
    "label": "Boolean"
  },
  "default_value": null,
  "is_required": false,
  "is_visible": false,
  "is_searchable": true,
  "is_filterable": true,
  "is_variant": false,
  "is_variant_listable": false,
  "name": "forbidden",
  "is_form_required": false,
  "is_form_field_required": false,
  "erp_code": "forbidden",
  "pre_attribute": false,
  "description": null,
  "modified_date": "2017-01-21T14:54:14.364000Z",
  "created_date": "2016-12-14T15:01:20.124000Z",
  "entity_type": 1,
  "visible_values": [
    {
      "pk": 3852,
      "attribute": 269,
      "value": "no",
      "order": null,
      "label": null,
      "erp_code": "false"
    },
    {
      "pk": 3851,
      "attribute": 269,
      "value": "yes",
      "order": null,
      "label": null,
      "erp_code": "true"
    }
  ]
}
```

### `GET` Attribute Translations

Path: `/api/v1/attributes/{pk}/translations/`

Brings the recorded localization values for the Attribute. Only the "name" parameter can be localized for the Attribute.

**Response**

```json
{
    "translations": {
        "fr-fr": {
            "name": "Taille"
        },
        "ar": {
            "name": "بحجم"
        },
        "tr-tr": {
            "name": "Beden"
        }
    }
}
```

## Attribute Set API Methods

### `GET` Attribute Sets

Path: `/api/v1/attribute_set/`

Brings the attribute values from the AttributeSet table. Gets the filter parameters in `AttributeSetFilter {omnitron.products.resources.filters.AttributeSetFilter}` as query parameters. Supports pagination with ViewSet’s inheritance from ListModelMixin with query parameters of page=X and limit=Y.

**AttributeSetFilter**

Used in listing operations with GET used in AttributeSetViewSet. It can get the following parameters as a filter.

* attribute\_set\_type: Contains AttributeSet type, takes AttributeSetTypes enum values.
* name: The namespace for the AttributeSet. It only needs to contain this value and works as case-sensitive.

### `GET` Attribute Sets by Attribute Set Type

Filters can be used with GET requests as follows.

Path: `api/v1/attribute_set/?attribute_set_type=simple/`

**Response**

```json
{
  "count": 51,
  "next": "https://{customer_omnitron_url}/api/v1/attribute_set/?attribute_set_type=simple&page=2",
  "previous": null,
  "results": [
    {
      "pk": 842,
      "name": "testacc1",
      "attribute_set_type": "simple",
      "attributeconfig_set": [
        {
          "pk": 3148,
          "attribute": 303,
          "attribute_set": 842,
          "is_required": false,
          "is_visible": true,
          "is_searchable": true,
          "is_filterable": true,
          "is_variant": false,
          "is_variant_listable": false,
          "default_fields": [
            "is_localizable"
          ],
          "order": 0,
          "is_form_required": false,
          "is_form_field_required": false
        }
      ],
    "description": null,
    "modified_date": "2021-11-10T17:42:33.171630Z",
    "created_date": "2017-01-20T19:02:43.782000Z"
    }
  ]
}
```

### `POST` Create Attribute Set

Path: `/api/v1/attribute_set/`

Adds a new record to the AttributeSet table. It is validated with AttributeSetSerializer. If the data is not suitable, it returns HTTP400. If there is an error or non-compliance in the service layer during the recording process, it returns HTTP406.

```json
{
    "name": "TestAttributeSet",
    "attribute_set_type": "simple",
    "description": "Test AttributeSet"
}
```

**Response**

```json
{
    "pk": 1040,
    "name": "TestAttributeSet",
    "attribute_set_type": "simple",
    "attributeconfig_set": [],
    "description": "Test AttributeSet",
    "modified_date": "2023-01-05T06:00:48.144781Z",
    "created_date": "2023-01-05T06:00:48.144761Z"
}
```

**Errors**

```json
{
    "name": [
        "attribute set with this name already exists."
    ]
}
```

### `DELETE` Attribute Set

Path: `/api/v1/attribute_set/{pk}/`

Deletes the object of the relevant primary key from the AttributeSet table. If it cannot find the object, it returns HTTP404.

Response: HTTP204

### `GET` Attribute Set

Path: `/api/v1/attribute_set/{pk}/`

Gets the object of the relevant primary key from the AttributeSet table. If it cannot find the object, it returns HTTP404.

**Response**

```json
{
    "pk": 1040,
    "name": "TestAttributeSet",
    "attribute_set_type": "simple",
    "attributeconfig_set": [],
    "description": "Test AttributeSet"
}
```

### `PATCH` Update Attribute Set

Path: `/api/v1/attribute_set/{pk}/`

Partially updates the object of the relevant primary key from the AttributeSet table. It is validated with AttributeSetSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With a partial update behavior, it only updates the sent parameters.

**Body**

```json
{
    "name": "TestAttributeSet1"
}
```

**Response**

```json
{
    "pk": 72,
    "name": "TestAttributeSet1",
    "attribute_set_type": "simple",
    "attributeconfig_set": [],
    "description": "Test AttributeSet",
    "modified_date": "2023-01-05T06:02:54.953317Z",
    "created_date": "2023-01-05T06:00:48.144761Z"
}
```

**HTTP 200**

**Errors**

```json
{
    "name": [
        "attribute set with this name already exists."
    ]
}
```

### `PUT` Update Attribute Set

Path: `/api/v1/attribute_set/{pk}/`

Updates the object of the relevant primary key from the AttributeSet table. It is validated with AttributeSetSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With an update behavior, it updates the entire object.

**Body**

```json
{
    "name": "TestAttributeSet2",
    "attribute_set_type": "simple"
}
```

**Response**

```json
{
    "name": "TestAttributeSet2",
    "attribute_set_type": "simple",
    "attributeconfig_set": [],
    "description": "Test AttributeSet add new description",
    "modified_date": "2023-01-05T06:14:59.870777Z",
    "created_date": "2023-01-05T06:00:48.144761Z"
}
```

**HTTP 200**

**Errors**

```json
{
    "attribute_set_type": [
        "This field is required."
    ]
}
```

### `GET` Attribute Sets Details

Path: `/api/v1/attribute_set/detailed/`

Exhibits the same behavior as AttributeSet listing, but the return parameters are more detailed. It also gets individual Attribute values in "attributeconfig\_set."

**Response:**

```json
{
    "count": 73,
    "next": "http://localhost:8000/api/v1/attribute_set/detailed/?page=2",
    "previous": null,
    "results": [
         {
            "pk": 72,
            "name": "TestAttributeSet2",
            "attribute_set_type": {
                "value": "simple",
                "label": "Simple"
            },
            "attributeconfig_set": [],
            "description": "Test AttributeSet add new description",
            "modified_date": "2023-01-05T06:16:28.507891Z",
            "created_date": "2023-01-05T06:00:48.144761Z"
        }
     ...
     ]
}
```

### `GET` Attribute Set Detail by Attribute Set Type

Path: `api/v1/attribute_set/detailed/?attribute_set_type=simple/`

**Response**

```json
{
  "count": 61,
  "next": "https://{customer_omnitron_url}/api/v1/attribute_set/detailed/?page=2",
  "previous": null,
  "results": [
    {
      "pk": 842,
      "name": "testacc1",
      "attribute_set_type": {
        "value": "simple",
        "label": "Simple"
      },
      "attributeconfig_set": [
        {
          "pk": 3148,
          "attribute": {
            "pk": 303,
            "key": "123",
            "data_type": "dropdown",
            "default_value": null,
            "is_required": false,
            "is_visible": true,
            "is_searchable": true,
            "is_filterable": true,
            "is_variant": false,
            "is_variant_listable": false,
            "name": "12344",
            "is_form_required": false,
            "is_form_field_required": false,
            "erp_code": "1234444",
            "pre_attribute": false,
            "description": null
          },
          "attribute_set": 842,
          "is_required": false,
          "is_visible": true,
          "is_searchable": true,
          "is_filterable": true,
          "is_variant": false,
          "is_variant_listable": false,
          "default_fields": [
            "is_localizable"
          ],
          "order": 0,
          "is_form_required": false,
          "is_form_field_required": false
        },
        {
          "pk": 2923,
          "attribute": {
            "pk": 1128,
            "key": "acctestattribute2",
            "data_type": "dropdown",
            "default_value": 4911,
            "is_required": true,
            "is_visible": true,
            "is_searchable": true,
            "is_filterable": true,
            "is_variant": true,
            "is_variant_listable": true,
            "name": "acctestattribute2",
            "is_form_required": false,
            "is_form_field_required": false,
            "erp_code": "acctestattribute2",
            "pre_attribute": false,
            "description": "acctestattribute2"
          },
          "attribute_set": 842,
          "is_required": true,
          "is_visible": true,
          "is_searchable": true,
          "is_filterable": true,
          "is_variant": true,
          "is_variant_listable": true,
          "default_fields": [
            "is_localizable"
          ],
          "order": 2,
          "is_form_required": false,
          "is_form_field_required": false
        }
      ],
      "description": null,
      "modified_date": "2023-01-05T06:16:28.507891Z",
      "created_date": "2023-01-05T06:00:48.144761Z"

    }
  ]
}

```

### `GET` Attribute Set Detail

Path: `/api/v1/attribute_set/{pk}/detailed/`

Exhibits the same behavior as getting AttributeSets, but the return parameters are more detailed. It also gets individual Attribute values in "attributeconfig\_set."

**Response**

```json
{
  "pk": 1040,
  "name": "TestAttributeSet",
  "attribute_set_type": {
    "value": "simple",
    "label": "Simple"
  },
  "attributeconfig_set": [],
  "description": "Test AttributeSet"
}

```

## Attribute Config API Methods

### `GET` Attribute Configs

Path: `/api/v1/attribute_config/`

Gets the values in the AttributeConfig table. Gets the filter parameters with `{omnitron.products.resources.filters.AttributeConfigFilter}` in AttributeConfigFilter as query parameters. Supports pagination with ViewSet’s inheritance from ListModelMixin with query parameters of page=X and limit=Y.

**AttributeConfigFilter**

Used in listing operations with GET used in AttributeConfigViewSet. It can get the following parameters as a filter.

* attribute: pk value of the relevant Attribute object.
* attribute\_set: pk value of the relevant AttributeSet object.

### `GET` Attribute Config by Attribute

Path: `api/v1/attribute_config/?attribute={pk}`

**Response**

```json
{
  "count": 14,
  "next": "https://{customer_omnitron_url}/api/v1/attribute_config/?attribute=303&page=2",
  "previous": null,
  "results": [
    {
      "pk": 1300,
      "attribute": 303,
      "attribute_set": 3,
      "is_required": false,
      "is_visible": true,
      "is_searchable": true,
      "is_filterable": true,
      "is_variant": false,
      "is_variant_listable": false,
      "default_fields": [
        "is_localizable"
      ],
      "order": 0,
      "is_form_required": false,
      "is_form_field_required": false,
      "modified_date": "2018-08-15T12:12:19.394963Z",
      "created_date": "2017-01-21T16:47:12.115000Z",
      "is_localizable": false

    }
  ]
}

```

### `POST` Create Attribute Config

Path: `/api/v1/attribute_config/`

Adds a new record to the AttributeConfig table. It is validated with AttributeConfigSerializer. If the data is not suitable, it returns HTTP400. If there is an error or non-compliance in the service layer during the recording process, it returns HTTP406.

**Body**

```json
{
    "attribute": 995,
    "attribute_set": 842,
    "is_required": false,
    "is_visible": true,
    "is_searchable": true,
    "is_filterable": true,
    "is_variant": false,
    "is_variant_listable": false,
    "is_form_required": false,
    "is_form_field_required": false
}
```

**Response**

```json
{
    "pk": 2447,
    "attribute": 1,
    "attribute_set": 72,
    "is_required": false,
    "is_visible": true,
    "is_searchable": true,
    "is_filterable": true,
    "is_variant": false,
    "is_variant_listable": false,
    "default_fields": [
        "is_localizable"
    ],
    "order": 0,
    "is_form_required": false,
    "is_form_field_required": false,
    "modified_date": "2023-01-05T06:26:12.416073Z",
    "created_date": "2023-01-05T06:26:12.416053Z",
    "is_localizable": false
}

```

**Errors**

```json
{
    "attribute": [
        "Invalid pk \"995\" - object does not exist."
    ],
    "attribute_set": [
        "Invalid pk \"842\" - object does not exist."
    ]
}
-- OR
{
  "code": "attribute_config_203_5",
  "en": "Multiple type attribute cannot assign to an attribute set"
}
-- OR
{
    "non_field_errors": [
        "The fields attribute, attribute_set must make a unique set."
    ]
}
-- OR
{
    "code": "attribute_config_203_3",
    "en": "Attribute config custom attribute set validation error. Custom attribute set doesn't accept variant attribute"
}
-- OR
{
    "code": "attribute_config_203_4",
    "en": "This attribute cannot exist in custom attribute set and attribute set"
}
```

### `DELETE` Attribute Config

Path: `/api/v1/attribute_config/{pk}/`

Deletes the object of the relevant primary key from the AttributeConfig table. If it cannot find the object, it returns HTTP404.

Response: HTTP204

### `GET` Attribute Config

Path: `/api/v1/attribute_config/{pk}/`

Gets the object of the relevant primary key from the AttributeSet table. If it cannot find the object, it returns HTTP404.

**Response**

```json
{
    "pk": 3247,
    "attribute": 995,
    "attribute_set": 842,
    "is_required": false,
    "is_visible": true,
    "is_searchable": true,
    "is_filterable": true,
    "is_variant": false,
    "is_variant_listable": false,
    "default_fields": ["is_localizable"],
    "order": 5,
    "is_form_required": false,
    "is_form_field_required": false
}

```

### `PATCH` Update Attribute Config

Path: `/api/v1/attribute_config/{pk}/`

Partially updates the object of the relevant primary key from the AttributeConfig table. It is validated with AttributeConfigSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With a partial update behavior, it only updates the sent parameters.

**Body**

```json
{
    "is_visible": true
}
```

**Response**

```json
{
    "pk": 2447,
    "attribute": 1,
    "attribute_set": 72,
    "is_required": false,
    "is_visible": true,
    "is_searchable": true,
    "is_filterable": true,
    "is_variant": false,
    "is_variant_listable": false,
    "default_fields": [
        "is_localizable"
    ],
    "order": 0,
    "is_form_required": false,
    "is_form_field_required": false,
    "modified_date": "2023-01-05T06:34:27.218889Z",
    "created_date": "2023-01-05T06:26:12.416053Z",
    "is_localizable": false
}
```

**Errors**

```json
{
    "attribute_set": [
        "Invalid pk \"700\" - object does not exist."
    ]
}
-- OR
{
    "attribute": [
        "Invalid pk \"10000\" - object does not exist."
    ]
}
-- OR
{
    "non_field_errors": [
        "The fields attribute, attribute_set must make a unique set."
    ]
}
-- OR
{
    "non_field_errors": "Attribute config custom attribute set validation error. Custom attribute set doesn't accept variant attribute",
    "error_code": "attribute_config_203_3"
}
```

### `PUT` Update Attribute Config

Path `/api/v1/attribute_config/{pk}/`

Updates the object of the relevant primary key from the AttributeConfig table. It is validated with AttributeConfigSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With an update behavior, it updates the entire object.

**Body**

```json
{
    "attribute": 1,
    "attribute_set": 72,
    "is_required": false,
    "is_visible": true,
    "is_searchable": true,
    "is_filterable": true,
    "is_variant": true,
    "is_variant_listable": false,
    "is_form_required": false,
    "is_form_field_required": false
}
```

**Response**

```json
{
    "pk": 2447,
    "attribute": 1,
    "attribute_set": 72,
    "is_required": false,
    "is_visible": true,
    "is_searchable": true,
    "is_filterable": true,
    "is_variant": true,
    "is_variant_listable": false,
    "default_fields": [
        "is_localizable"
    ],
    "order": 0,
    "is_form_required": false,
    "is_form_field_required": false,
    "modified_date": "2023-01-05T07:12:55.475601Z",
    "created_date": "2023-01-05T06:26:12.416053Z",
    "is_localizable": false
}
```

**Errors**

```json
{
    "is_visible": [
        "This field is required."
    ],
    "is_variant_listable": [
        "This field is required."
    ],
    "attribute": [
        "This field is required."
    ],
    "is_form_required": [
        "This field is required."
    ],
    "is_filterable": [
        "This field is required."
    ],
    "is_searchable": [
        "This field is required."
    ],
    "is_form_field_required": [
        "This field is required."
    ],
    "attribute_set": [
        "This field is required."
    ],
    "is_required": [
        "This field is required."
    ]
}
```

### `GET` Attribute Configs Details

Path: `/api/v1/attribute_config/detailed/`

Exhibits the same behavior as AttributeSet listing, but the return parameters are more detailed. Gets the associated attribute value in detail.

**Response**

```json
{
  "count": 14,
  "next": "https://{customer_omnitron_url}/api/v1/attribute_config/detailed/?attribute=303&page=2",
  "previous": null,
  "results": [
    {
      "pk": 1300,
      "attribute": {
        "pk": 303,
        "key": "123",
        "data_type": "dropdown",
        "default_value": null,
        "is_required": false,
        "is_visible": true,
        "is_searchable": true,
        "is_filterable": true,
        "is_variant": false,
        "is_variant_listable": false,
        "name": "12344",
        "is_form_required": false,
        "is_form_field_required": false,
        "erp_code": "1234444",
        "pre_attribute": false,
        "description": null
      },
      "attribute_set": 3,
      "is_required": false,
      "is_visible": true,
      "is_searchable": true,
      "is_filterable": true,
      "is_variant": false,
      "is_variant_listable": false,
      "default_fields": [
        "is_localizable"
      ],
      "order": 0,
      "is_form_required": false,
      "is_form_field_required": false
    }
  ],
  "modified_date": "2022-12-29T11:26:06.800700Z",
  "created_date": "2022-12-29T11:26:06.800693Z",
  "is_localizable": false
}
```

### `GET` Attribute Config Detail

Path: `/api/v1/attribute_config/{pk}/detailed/`

Exhibits the same behavior as getting AttributeConfigs, but the return parameters are more detailed. Gets the associated attribute value in detail.

**Response**

```json
{
  "pk": 1300,
  "attribute": {
    "pk": 303,
    "key": "123",
    "data_type": "dropdown",
    "default_value": null,
    "is_required": false,
    "is_visible": true,
    "is_searchable": true,
    "is_filterable": true,
    "is_variant": false,
    "is_variant_listable": false,
    "name": "12344",
    "is_form_required": false,
    "is_form_field_required": false,
    "erp_code": "1234444",
    "pre_attribute": false,
    "description": null
  },
  "attribute_set": 3,
  "is_required": false,
  "is_visible": true,
  "is_searchable": true,
  "is_filterable": true,
  "is_variant": false,
  "is_variant_listable": false,
  "default_fields": [
    "is_localizable"
  ],
  "order": 0,
  "is_form_required": false,
  "is_form_field_required": false,
  "modified_date": "2023-01-05T07:12:55.475601Z",
  "created_date": "2023-01-05T06:26:12.416053Z",
  "is_localizable": false
}
```

## Attribute Value API Methods

### `GET` Attribute Values

Path: `/api/v1/attribute_value/`

Gets the values in the AttributeValue table. Gets the filter parameters in `AttributeValueFilter {omnitron.products.resources.filters.AttributeValueFilter}` as query parameters. Supports pagination with ViewSet’s inheritance from ListModelMixin with query parameters of page=X and limit=Y.

**AttributeValueFilter**

Used in listing operations with GET used in AttributeValueViewSet. It can get the following parameters as a filter.

* label: The title field for the AttributeValue. It only needs to contain this value and works as case-sensitive.
* erp\_code: The erp code field for the AttributeValue. It only needs to contain this value.
* value: The value field for the AttributeValue. It only needs to contain this value.
* value\_\_exact: The value field for the AttributeValue. It requires a complete match.
* attribute: pk value of the relevant Attribute object.

**Response**

```json
{
  "count": 20,
  "next": "https://{customer_omnitron_url}/api/v1/attribute_value/?attribute=667&page=2",
  "previous": null,
  "results": [
    {
      "pk": 4019,
      "attribute": 667,
      "value": "Beyaz",
      "order": null,
      "label": "White",
      "erp_code": "White",
      "modified_date": "2018-08-15T12:12:22.588620Z",
      "created_date": "2017-01-21T18:46:22.218000Z"

    },
    {
      "pk": 4020,
      "attribute": 667,
      "value": "Bordo",
      "order": null,
      "label": "Claret Red",
      "erp_code": "Claret Red",
      "modified_date": "2018-08-15T12:12:22.588620Z",
      "created_date": "2017-01-21T18:46:22.218000Z"
    }
  ]
}
```

### `POST` Create Attribute Value

Path: `/api/v1/attribute_value/`

Adds a new record to the AttributeValue table. It is validated with AttributeValueSerializer. If the data is not suitable, it returns HTTP400. If there is an error or non-compliance in the service layer during the recording process, it returns HTTP406.

```json
{
    "attribute": 995,
    "label": "Test",
    "value": "Test Value",
    "erp_code": "erp_test"
}
```

**Response**

```json
{
    "pk": 5072,
    "attribute": 995,
    "value": "Test Value",
    "order": null,
    "label": "Test",
    "erp_code": "erp_test",
    "modified_date": "2023-01-05T07:26:16.974706Z",
    "created_date": "2023-01-05T07:26:16.974689Z"
}
```

**Errors**

```json
{
    "attribute": [
        "Invalid pk \"995\" - object does not exist."
    ]
}
-- OR
{
    "non_field_errors": [
        "The fields attribute, value must make a unique set."
    ]
}

-- OR
{
    "non_field_errors": "... already exists",
    "error_code": "attribute_value_201_1"
}
```

### `GET` Attribute Value

Path: `/api/v1/attribute_value/{pk}/`

Gets the object of the relevant primary key from the AttributeValue table. If it cannot find the object, it returns HTTP404.

**Response**

```json
{
    "pk": 5072,
    "attribute": 995,
    "value": "Test Value",
    "order": null,
    "label": "Test",
    "erp_code": "erp_test",
    "modified_date": "2018-08-15T12:12:22.588620Z",
    "created_date": "2017-01-21T18:46:22.218000Z"
}
```

### `PATCH` Update Attribute Value

Path: `/api/v1/attribute_value/{pk}/`

Partially updates the object of the relevant primary key from the AttributeValue table. It is validated with AttributeValueSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With a partial update behavior, it only updates the sent parameters.

**Body**

```json
{
    "label": "Test1"
}
```

**Response**

```json
{
    "pk": 976,
    "attribute": 1,
    "value": "Test Value",
    "order": null,
    "label": "Test1",
    "erp_code": "erp_test",
    "modified_date": "2023-01-05T07:33:36.127252Z",
    "created_date": "2023-01-05T07:26:16.974689Z"
}
```

**Errors**

```json
{
    "non_field_errors": "... already exists",
    "error_code": "attribute_value_201_1"
}
-- OR
{
    "non_field_errors": ""AttributeValue can not be updated."",
    "error_code": "attribute_value_201_2"
}
```

### `PUT` Update Attribute Value

Path: `/api/v1/attribute_value/{pk}/`

Updates the object of the relevant primary key from the AttributeValue table. It is validated with AttributeValueSerializer. If the data is not suitable, it returns HTTP400. If it cannot find the object, it returns HTTP404. With an update behavior, it updates the entire object.

**Body**

```json
{
    "attribute": 1,
    "label": "Test2",
    "value": "Test Value",
    "erp_code": "erp_test"
}
```

**Response**

```json
{
    "pk": 976,
    "attribute": 1,
    "value": "Test Value",
    "order": null,
    "label": "Test2",
    "erp_code": "erp_test",
    "modified_date": "2023-01-05T07:41:09.023560Z",
    "created_date": "2023-01-05T07:26:16.974689Z"
}
```

**Errors**

```json
{
    "attribute": [
        "This field is required."
    ],
    "value": [
        "This field is required."
    ],
    "erp_code": [
        "This field is required."
    ]
}
```

### `DELETE` Attribute Value

Path: `/api/v1/attribute_value/{pk}/`

Deletes the object of the relevant primary key from the AttributeConfig table. If it cannot find the object, it returns HTTP404.

Response: HTTP204

### `GET` Attribute Values Details

Path: `/api/v1/attribute_value/detailed/`

Exhibits the same behavior as AttributeValue listing, but the return parameters are more detailed. Gets the associated attribute value in detail.

**Response**

```json
{
  "count": 20,
  "next": "https://{customer_omnitron_url}/api/v1/attribute_value/detailed/?attribute=667&page=2",
  "previous": null,
  "results": [
    {
      "pk": 4019,
      "value": "White",
      "order": null,
      "label": "White",
      "attribute": {
        "pk": 667,
        "key": "mp_filterable_color",
        "data_type": "dropdown",
        "default_value": 4035,
        "is_required": false,
        "is_visible": true,
        "is_searchable": true,
        "is_filterable": true,
        "is_variant": false,
        "is_variant_listable": false,
        "name": "MP Filtrable Color",
        "is_form_required": false,
        "is_form_field_required": false,
        "erp_code": "mp_filterable_color",
        "pre_attribute": false,
        "description": null,
        "modified_date": "2023-01-05T07:41:09.023560Z",
        "created_date": "2023-01-05T07:26:16.974689Z",
        "entity_type": 1
      },
    },
    {
      "pk": 4020,
      "value": "Claret Red",
      "order": null,
      "label": "Claret Red",
      "attribute": {
        "pk": 667,
        "key": "mp_filterable_color",
                "data_type": "dropdown",
        "default_value": 4035,
        "is_required": false,
        "is_visible": true,
        "is_searchable": true,
        "is_filterable": true,
        "is_variant": false,
        "is_variant_listable": false,
        "name": "MP Filtrable Color",
        "is_form_required": false,
        "is_form_field_required": false,
        "erp_code": "mp_filterable_color",
        "pre_attribute": false,
        "description": null,
        "modified_date": "2023-01-05T07:41:09.023560Z",
        "created_date": "2023-01-05T07:26:16.974689Z",
        "entity_type": 1
      }
    }
  ]
}
```

### `GET` Attribute Value Detail

Path: `/api/v1/attribute_value/{pk}/detailed/`

Exhibits the same behavior as getting AttributeValue, but the return parameters are more detailed. Gets the associated attribute value in detail.

**Response**

```json
{
    "pk": 4019,
    "value": "White",
    "order": null,
    "label": "White",
    "attribute": {
        "pk": 667,
        "key": "mp_filterable_color",
        "data_type": "dropdown",
        "default_value": 4035,
        "is_required": false,
        "is_visible": true,
        "is_searchable": true,
        "is_filterable": true,
        "is_variant": false,
        "is_variant_listable": false,
        "name": "MP Filtrable Color",
        "is_form_required": false,
        "is_form_field_required": false,
        "erp_code": "mp_filterable_color",
        "pre_attribute": false,
        "description": null,
        "modified_date": "2017-01-21T14:54:14.359000Z",
        "created_date": "2016-12-14T14:56:02.160000Z",
        "entity_type": 1
    }
}
```

### `GET` Attribute Value Translations

Path: `/api/v1/attribute_value/{pk}/translations/`

Brings the recorded localization values for the AttributeValue. Only the "label" parameter can be localized for the AttributeValue.

**Response**

```json
{
  "translations": {
    "en-us": {
      "label": "White"
    },
    "tr-tr": {
      "label": "Beyaz"
    }
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.akinon.com/omnitron/pim/attributes-and-sets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
