# Product Category

## List Product Categories

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

This API endpoint will return a list of the product category (product-type)

#### Query Parameters

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| offset | string |             |
| limit  | string |             |

#### 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 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "results": [
            {
                "id": <category_id>,
                "name": "<category_name>",
                "status": <status>,
                "has_inventory": <has_inventory_boolean>,
                "has_recurring": <has_recurring_boolean>,
                "has_variants": <has_variants_boolean>,
                "has_shippable": <has_shippable_boolean>,
                "has_discount": <has_discount_boolean>,
                "created": "<created_date>",
                "modified": "<modified_date>",
                "data": {
                    "tax": {
                        "method": "<method_name>",
                        "method_status": <status>
                    },
                    "afl_fees": {
                        "method": "<method_name>",
                        "method_status": <status>
                    },
                    ...
                },
                "slug": "<slug>"
            }
            ...
        ],
        "count": <list_count>,
        "previous": <previous_page_link>,
        "next": "<next_page_link>"
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/product/list/categories/',
  '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/categories/",
  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;
```

## Create Product Category

Create a Product category (Product - Type).

* First, Get the list of enabled product type method configuration through the below-provided endpoint.
* Then Create product type through the post method.

### Active Product Type Method Configurations

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

This API endpoint will return  enabled product type method configurations

#### 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 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "EnabledProductTypeMethodConf": [
            {
                "method": "<method_name>",
                "weight": <weight>,
                "title": "<method_title>",
                "description": "<method_description>",
                "attr_slug": [],
                "disabled_status": <status>
            },
            ...
        ]
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/product/get/producttype/methodconf/',
  '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/producttype/methodconf/',
  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;

```

### Create Product Type

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

This API endpoint will create a product type.

#### 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>           | string | Method name                                                                                                                                                                                           |
| translations<mark style="color:red;">\*</mark>   | object | name translations for name                                                                                                                                                                            |
| method<mark style="color:red;">\*</mark>         | array  | <p>An array of the string contains method names</p><p><a data-mention href="#active-product-type-method-configurations">#active-product-type-method-configurations</a></p>                            |
| catalogue\_ids<mark style="color:red;">\*</mark> | array  | <p>An array of integer contains catalogue ids</p><p><a data-mention href="../product-catalogue#list-catalogues">#list-catalogues</a></p>                                                              |
| attr\_grp\_ids<mark style="color:red;">\*</mark> | array  | <p>An array of integerS contains product attribute group ids,<br>Require at least  one group id</p><p><a data-mention href="../group-attributes#list-attributes-group">#list-attributes-group</a></p> |

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

```
​HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

Body Parameters are JSON.stringify, Refer below block for the body parameter structure, and also refer sample code.

```php
{
    "name": "<product-type-name>",
    "translations": {
        "<language_code>": "<name>",
        "<language_code>": "<name>",
        ...
    },
    "method": [
        "<method_name>",
        "<method_name>",
        ...
    ],
    "catalogue_ids": [
        <catalogue_id>,
        <catalogue_id>,
        ...
    ],
    "attr_grp_ids": [
        <attr_grp_ids>,
        <attr_grp_ids>,
        ...
    ]
}
```

#### Sample Code

**Node**

```php
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/product/create/category/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"name":"<method-name>","translations":{"<language_code>":"<name>","<language_code>":"<name>"},"method":["<method_name>","<method_name>"],"catalogue_ids":[<id>,<id>],"attr_grp_ids":[<id>,<id>]})
};
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/category/',
  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": "<method_name>",
    "translations": {
        "<language_code>": "<name>",
        "<language_code>": "<name>"
    },
    "method": [
        "<method_name>",
        "<method_name>"
    ],
    "catalogue_ids": [
        <id>,
        <id>
    ],
    "attr_grp_ids": [
        <id>,
        <id>
    ]
}',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>',
    'Content-Type: application/json',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

#### Error Responses

| Status Code | Error Type       | FIeld          | Description                                                                                                                              |
| ----------- | ---------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| 400         | Validation Error | name           | <p>This field is required.</p><p>This field may not be blank.</p><p>Ensure this field has no more than 250 characters.</p>               |
| 400         | Validation Error | catalogue\_ids | <p>Provided \<catalogue\_ids> is not a valid catalogue id</p><p>Provided \<catalogue\_ids> does not exist</p>                            |
| 400         | Validation Error | attr\_grp\_ids | <p>Provide at least one group</p><p>Provided \<attr\_grp\_id> is not a valid group id</p><p>Provided \<attr\_grp\_id> does not exist</p> |

## Update Product Category

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

This API endpoint will update a product category.

#### 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                                                                                                   |
| ------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------- |
| ptype<mark style="color:red;">\*</mark>          | integer | Product type id                                                                                               |
| name<mark style="color:red;">\*</mark>           | string  | New or existing name of the product type                                                                      |
| attr\_grp\_ids<mark style="color:red;">\*</mark> | array   | <p>Replace with a new array of integer or existing group ids,<br>Require at least one attribute group id.</p> |
| translations<mark style="color:red;">\*</mark>   | object  | name translations for name                                                                                    |
| method<mark style="color:red;">\*</mark>         | array   | An array of the string contains method names                                                                  |
| catalogue\_ids<mark style="color:red;">\*</mark> | array   | An array of integer contains catalogue ids                                                                    |

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

```
​HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

Body Parameters are JSON.stringify, Refer below block for the body parameter structure, and also refer sample code.

```php
{    
    "ptype":<product_typ>,
    "name": "<product-type-name>",
    "translations": {
        "<language_code>": "<name>",
        "<language_code>": "<name>",
        ...
    },
    "method": [
        "<method_name>",
        "<method_name>",
        ...
    ],
    "catalogue_ids": [
        <catalogue_id>,
        <catalogue_id>,
        ...
    ],
    "attr_grp_ids": [
        <attr_grp_ids>,
        <attr_grp_ids>,
        ...
    ]
}
```

#### Sample Code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/product/update/category/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"ptype":<product_type_id>,"name":"<name>","attr_grp_ids":[<id>,<id>],"translations":{"<language_code>":"<name>","<language_code>":"<name>"},"method":["<method_name>","<method_name>"],"catalogue_ids":[<id>,<id>]})

};
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/category/',
  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 =>'{
    "ptype":<product_type_id>,
    "name":"<name>",
    "attr_grp_ids":[
        <id>,
        <id>
    ],
    "translations": {
        "<language_code>":"<name>",
        "<language_code>":"<name>"
    },
    "method": [
        <method_name>",
        <method_name>"
    ],
     "catalogue_ids": [
        <id>,
        <id>         
    ]
}',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>',
    'Content-Type: application/json',
  ),
));

$response = curl_exec($curl);

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

#### Error Responses

| Status Code | Error Type       | FIeld          | Description                                                                                                                             |
| ----------- | ---------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 400         | Validation Error | ptype          | <p>Product Type id is required.</p><p>This field may not be blank.</p><p>Product Type does not exist.</p>                               |
| 400         | Validation Error | name           | <p>This field is required.</p><p>This field may not be blank.</p><p>Ensure this field has no more than 250 characters.</p>              |
| 400         | Validation Error | catalogue\_ids | <p>Provided \<catalogue\_ids> is not a valid catalogue id</p><p>Provided \<catalogue\_ids> does not exist</p>                           |
| 400         | Validation Error | attr\_grp\_ids | <p>Provide at least one group</p><p>Provided \<attr\_grp\_id> is not a valid group id</p><p>Provided \<attr\_grp\_id> does not exis</p> |

## Delete Product Category

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

This API endpoint will delete a product category

#### Query Parameters

| Name                                 | Type   | Description         |
| ------------------------------------ | ------ | ------------------- |
| id<mark style="color:red;">\*</mark> | string | Product category id |

#### Headers

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

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

```markup
​HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "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/category/?id=<category_id>',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
  },
  formData: {}
};
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/category/?id=<category_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;

```

#### Error Responses

| Status Code | Error Type     | FIeld | Description                                                                                                                |
| ----------- | -------------- | ----- | -------------------------------------------------------------------------------------------------------------------------- |
| 400         | Invalid Input  | id    | <p>Category id is not valid.</p><p>Category does not exist.<br>This field may not be blank<br>Category id is required.</p> |
| 401         | Request Failed |       | <p>There are products in this category.you can't delete it</p><p>Category can't delete or remove</p>                       |
