Product Category

Manage product category

List Product Categories

get
https://<domain>/<api prefix>/<version>/commerce/product/list/categories/

Sample Code

Node
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
$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

get
https://<domain>/<api prefix>/<version>/commerce/product/get/producttype/methodconf/

Sample Code

Node
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
$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

post
https://<domain>/<api prefix>/<version>/commerce/product/create/category/
Body Parameters are JSON.stringify, Refer below block for the body parameter structure, and also refer sample code.
{
"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
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
$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
This field is required.
This field may not be blank.
Ensure this field has no more than 250 characters.
400
Validation Error
catalogue_ids
Provided <catalogue_ids> is not a valid catalogue id
Provided <catalogue_ids> does not exist
400
Validation Error
attr_grp_ids
Provide at least one group
Provided <attr_grp_id> is not a valid group id
Provided <attr_grp_id> does not exist

Update Product Category

post
https://<domain>/<api prefix>/<version>/commerce/product/update/category/
Body Parameters are JSON.stringify, Refer below block for the body parameter structure, and also refer sample code.
{
"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
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
$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
Product Type id is required.
This field may not be blank.
Product Type does not exist.
400
Validation Error
name
This field is required.
This field may not be blank.
Ensure this field has no more than 250 characters.
400
Validation Error
catalogue_ids
Provided <catalogue_ids> is not a valid catalogue id
Provided <catalogue_ids> does not exist
400
Validation Error
attr_grp_ids
Provide at least one group
Provided <attr_grp_id> is not a valid group id
Provided <attr_grp_id> does not exis

Delete Product Category

delete
https://<domain>/<api prefix>/<version>/commerce/product/delete/category/?id=<category_id>

Sample Code

Node
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
$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
Category id is not valid.
Category does not exist. This field may not be blank Category id is required.
401
Request Failed
There are products in this category.you can't delete it
Category can't delete or remove