JSON API
...
Examples
Batch Updates
Categories
1min
If you are using category merchandising and want to associate products with the categories, then first index a category item and then index products by creating their relationship with the category. Products can be mapped to multiple categories. Following is an example of how to do it.
[
{
"id": "men-shirts",
"type": "KLEVU_CATEGORY",
"attributes": {
"name": {
"default": "Shirts"
},
"url": "https://test.myshopify.com/collections/men-shirts",
"categoryPath": "Mens/Shirts"
}
},
{
"id": "1",
"type": "KLEVU_PRODUCT",
"relations": {
"categories": {
"values": [
"men-shirts"
]
}
},
"attributes": {
"name": {
"default": "Shirt"
},
"image": {
"default": {
"url": "https://4.imimg.com/data4/AO/DA/MY-24693421/comfortable-office-chair.jpg"
}
},
"url": "https://test.myshopify.com/products/black-shirt",
"shortDescription": {
"default": "This is a black shirt available in different sizes."
}
}
},
{
"id": "2",
"type": "KLEVU_PRODUCT",
"relations": {
"parentProduct": {
"values": [
"1"
]
},
"categories": {
"values": [
"men-shirts"
]
}
},
"attributes": {
"name": {
"default": "Shirt"
},
"image": {
"default": {
"url": "https://4.imimg.com/data4/AO/DA/MY-24693421/comfortable-office-chair.jpg"
}
},
"price": {
"GBP": {
"salePrice": 80
}
},
"url": "https://test.myshopify.com/products/black-shirt-s",
"shortDescription": {
"default": "Black Shirt"
},
"size": "s"
}
},
{
"id": "3",
"type": "KLEVU_PRODUCT",
"relations": {
"parentProduct": {
"values": [
"1"
]
},
"categories": {
"values": [
"men-shirts"
]
}
},
"attributes": {
"name": {
"default": "Shirt"
},
"image": {
"default": {
"url": "https://4.imimg.com/data4/AO/DA/MY-24693421/comfortable-office-chair.jpg"
}
},
"price": {
"GBP": {
"salePrice": 100
}
},
"url": "https://test.myshopify.com/products/black-shirt-m",
"shortDescription": {
"default": "Black Shirt"
},
"size": "m"
}
}
]
- For a complex product, ensure mapping all variants to the category.
- Items of different types like categories, products, etc can be part of the same request payload.
- Order should be maintained when objects are being related i.e. If you are mapping a product to a category, then the category should be created before the product.