# Product Attribute

### Create attribute

<mark style="color:green;">`POST`</mark> `‎‎ https://<domain>/<api prefix>/<version>/commerce/product/create/attribute/`

This endpoint will help to create a new attribute to the system

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name                                          | Type    | Description                                                                                                                                        |
| --------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| name<mark style="color:red;">\*</mark>        | dict    | Attribute name, eg: {"en":"\<name>"}                                                                                                               |
| description<mark style="color:red;">\*</mark> | dict    | Attribute description, eg:{"en":"\<description>"}                                                                                                  |
| data\_type<mark style="color:red;">\*</mark>  | string  | Data type, possible values are **String, Integer, Float, and Boolean.**                                                                            |
| widget<mark style="color:red;">\*</mark>      | string  | Supported widgets are **select\_box, radio\_button, color\_box, textfield, textarea, and datepicker**.                                             |
| options<mark style="color:red;">\*</mark>     | array   | <p>contains at least one dict with the following keys</p><p>{"status": \<boolean>,"label":"\<string>","value":"\<string>","weight":\<integer>}</p> |
| is\_unique                                    | boolean |                                                                                                                                                    |
| is\_display                                   | boolean |                                                                                                                                                    |
| is\_required                                  | boolean |                                                                                                                                                    |
| attribute\_for                                | string  | general or varients                                                                                                                                |

{% tabs %}
{% tab title="200 " %}

```
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**&#x20;

```javascript
var request = require('request');
var options = {
  'method': 'POST',
  'url': '‎ https://<domain>/<api prefix>/<version>/commerce/product/create/attribute/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>'
  },
  body: JSON.stringify({"name":{"en":"<name in english>","de":"<name in german>"},"data_type":"<attribute data type>","attribute_for":"<attribute for>","widget":"<widget type>","description":{"en":"<description in english>","de":"<description in german>"},"is_unique":"<is unique value>","is_required":"<is required>","is_display":"<need to display>","options":[{"status":"<attribute option status>","label":"<attribute option label>","value":"<attirbute option value>","weight":"<attirbute option weight>"},{"status":"<attribute option status>","label":"<attribute option label>","value":"<attirbute option value>","weight":"<attirbute option weight>"}]})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/product/create/attribute/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"{\"name\":{\"en\":\"<name in english>\",\"de\":\"<name in german>\"},\"data_type\":\"<attribute data type>\",\"attribute_for\":\"<attribute for>\",\"widget\":\"<widget type>\",\"description\":{\"en\":\"<description in english>\",\"de\":\"<description in german>\"},\"is_unique\":\"<is unique value>\",\"is_required\":\"<is required>\",\"is_display\":\"<need to display>\",\"options\":[{\"status\":\"<attribute option status>\",\"label\":\"<attribute option label>\",\"value\":\"<attirbute option value>\",\"weight\":\"<attirbute option weight>\"},{\"status\":\"<attribute option status\",\"label\":\"<attribute option label>\",\"value\":\"<attirbute option value>\",\"weight\":\"<attirbute option weight>\"}]}",
  CURLOPT_HTTPHEADER => array(
    "apikey: <apikey>",
    "Authorization: Bearer <access token>"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

#### Error Responses

| Status Code | Error Type       | Field       | Description                                                                                                    |
| ----------- | ---------------- | ----------- | -------------------------------------------------------------------------------------------------------------- |
| 400         | Validation Error | name        | Name for {language code}  language is required.                                                                |
| 400         | Validation Error | description | <p>Description for {language code} langauge is required.</p><p></p>                                            |
| 400         | Validation Error | widget      | {widget name} is not a valid choice. Supported widgets are {widgets}.                                          |
| 400         | Validation Error | widget      | {widget name} is not a valid choice. Supported widgets for data type {data type} is/are {widget/widgets}.      |
| 400         | Validation Error | data\_type  | {data\_type} is not a valid choice. Supported data types are {data}.                                           |
| 400         | Validation Error | widget      | {widget} widget can't be selected for an {data\_type} data type.                                               |
| 400         | Validation Error | options     | The selected widget-data\_type attribute doesn't support any options. leave it as empty or no need to mention. |
| 400         | Validation Error | options     | This field is required.                                                                                        |
| 400         | Validation Error | name        | All languages of names must have a description of the corresponding language.                                  |

### List Attributes

<mark style="color:blue;">`GET`</mark> `‎‎ https://<domain>/<api prefix>/<version>/commerce/product/list/attributes/`

This endpoint will return list of available product attributes

#### Query Parameters

| Name     | Type   | Description  |
| -------- | ------ | ------------ |
| en\_name | string | English name |

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

{% tabs %}
{% tab title="200 " %}

```html
{
    "status_code": 200,
    "errors": {},
    "data": {
        "results": [
            {
                "id": <id>,
                "name": {
                    "en": "<name in english>",
                    "de": "<name in german>"
                },
                "description": {
                    "en": "<description in english>",
                    "de": "<description in german>"
                },
                "widget": "<widget type>",
                "attribute_for": "<attribute for>",
                "is_unique": <is unique value>,
                "is_required": <is required>,
                "is_display": <need to display>,
                "options": [
                    {
                        "label": "<attribute option label>",
                        "value": "<attirbute option value>",
                        "status": <attribute option status>,
                        "weight": <attirbute option weight>
                    },
                    {
                        "label": "<attribute option label>",
                        "value": "<attirbute option value>",
                        "status": <attribute option status>,
                        "weight": <attirbute option weight>
                    }
                ],
                "data_type": "<attribute data type>",
                "status": 1
            }
        ],
        "count": <total attibutes count>,
        "previous": <previous url>,
        "next": <next url>
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Node

**Node**

```php
var request = require('request');
var options = {
  'method': 'GET',
  'url': '‎ https://<domain>/<api prefix>/<version>/commerce/product/list/attributes/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/product/list/attributes/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "apikey: <apikey>",
    "Authorization: Bearer <access token>"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

### Get A Attribute

<mark style="color:blue;">`GET`</mark> `‎https://<domain>/<api prefix>/<version>/commerce/product/get/attribute/<attribute id>/`

This endpoint will return a single attribute details

#### Headers

| Name                                             | Type   | Description         |
| ------------------------------------------------ | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>         | string | apikey              |
| Aurthorization<mark style="color:red;">\*</mark> | string | Bearer access token |

{% tabs %}
{% tab title="200 " %}

```html
{
    "status_code": 200,
    "errors": {},
    "data": {
        "id": <id>,
        "name": {
            "en": "<name in english>",
            "de": "<name in german>"
        },
        "description": {
            "en": "<description in english>",
            "de": "<description in german>"
        },
        "widget": "<widget type>",
        "attribute_for": "<attribute for>",
        "is_unique": <is unique value>,
        "is_required": <is required>,
        "is_display": <need to display>,
        "options": [
            {
                "label": "<attribute option label>",
                "value": "<attirbute option value>",
                "status": <attribute option status>,
                "weight": <attirbute option weight>
            },
            {
                "label": "<attribute option label>",
                "value": "<attirbute option value>",
                "status": <attribute option status>,
                "weight": <attirbute option weight>
            }
        ],
        "data_type": "<attribute data type>",
        "status": 1
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample code

**Node**

```php
var request = require('request');
var options = {
  'method': 'GET',
  'url': '‎https://<domain>/<api prefix>/<version>/commerce/product/get/attribute/<attribute id>/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/product/get/attribute/<attribute_id>/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "apikey: <apikey>",
    "Authorization: Bearer <access token"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

### Delete Attribute

<mark style="color:red;">`DELETE`</mark> `‎https://<domain>/<api prefix>/<version>/commerce/product/delete/attribute/<attribute id>/`

This endpoint will help to delete a product attribute from the system.

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

{% tabs %}
{% tab title="200 " %}

```
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample code

**Node**

```php
var request = require('request');
var options = {
  'method': 'DELETE',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/product/delete/attribute/<attribute_id>/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/commerce/product/delete/attribute/<attribute_id>/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'DELETE',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

### Update Attribute

<mark style="color:green;">`POST`</mark> `‎https://<domain>/<api prefix>/<version>/commerce/product/update/attribute/<attribute id>/`

This endpoint will help to edit a product attribute details.

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name | Type   | Description              |
| ---- | ------ | ------------------------ |
|      | String | Same as create attribute |

{% tabs %}
{% tab title="200 " %}

```
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample code

**Node**

```php
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/product/update/attribute/<attribute_id>/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
  },
  body: JSON.stringify({"name":{"en":"<name in english>","de":"<name in german>"},"data_type":"<attribute data type>","attribute_for":"<attribute for>","widget":"<widget type>","description":{"en":"<description in english>","de":"<description in german>"},"is_unique":"<is unique value>","is_required":"<is required>","is_display":"<need to display>","options":[{"status":"<attribute option status>","label":"<attribute option label>","value":"<attirbute option value>","weight":"<attirbute option weight>"},{"status":"<attribute option status>","label":"<attribute option label>","value":"<attirbute option value>","weight":"<attirbute option weight>"}]})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/commerce/product/update/attribute/<attribute_id>/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "name":{"en":"<name>"},
    "description":{"en":"<description>"},
    "data_type":"<data_type>",
    "widget":"<widget>",
    "options":[{"status": <status>,"label":"<attribute_option_label>","value":"<value>","weight":<weight>}]
}',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```
