Categorize products
This guide organizes your catalog with categories. You’ll build a small taxonomy - a tree of categories - and classify a product, so it ends up filed under “Shoes”, then describe it with a color attribute.
A category classifies products and nests under a parent; together, categories form a taxonomy (the tree).
Prerequisites
Section titled “Prerequisites”You need a product on an existing instance. If you don’t have one, follow Create your first product first.
As in the other guides, the commands below use the organization id (shown as <org_id>) and the instance handle (the tenant, shown as <tenant>). The example reuses one product id, 019af93e-... - replace it with your own.
Before you start
Section titled “Before you start”You need an OAuth 2.0 bearer token for a partner account. Sign in below and pick your organization and instance: an access token scoped to that instance is generated and dropped into every product-management command on this page. See Authentication for more.
Enter tenant & organization ID manually
-
Create a top-level category.
Start the tree with a parent. Capture its
@id- the child references it next.Terminal window curl -X POST 'https://<tenant>.product-management.flowkiwi.net/api/categories' \-H 'Authorization: Bearer {access_token}' \-H 'Content-Type: application/ld+json' \-d '{"status": "/api/statuses/ACTIVE","name": "Clothing"}'A write returns the whole resource; the excerpt below keeps its identity (see Write responses):
{"@context": "/api/contexts/Category","@id": "/api/categories/019afd01-1a2b-7c3d-8e4f-0a1b2c3d4e5f","@type": "Category","id": "019afd01-1a2b-7c3d-8e4f-0a1b2c3d4e5f"} -
Create a child category and classify the product.
Nest “Shoes” under “Clothing” with
parent, and file your product into it withproducts. Capture the child’s@id.Terminal window curl -X POST 'https://<tenant>.product-management.flowkiwi.net/api/categories' \-H 'Authorization: Bearer {access_token}' \-H 'Content-Type: application/ld+json' \-d '{"status": "/api/statuses/ACTIVE","name": "Shoes","parent": "/api/categories/019afd01-1a2b-7c3d-8e4f-0a1b2c3d4e5f","products": ["/api/products/019af93e-420e-79f8-800b-6680f03dce20"]}'{"@context": "/api/contexts/Category","@id": "/api/categories/019afd02-2b3c-7d4e-9f50-1a2b3c4d5e6f","@type": "Category","id": "019afd02-2b3c-7d4e-9f50-1a2b3c4d5e6f"}
Describe products with attributes
Section titled “Describe products with attributes”Categories can also carry attributes - a Color for “Shoes”, say - that the products filed under them describe themselves with:
- an attribute definition declares the attribute and the categories it applies to. Its
typeisstringfor free text, orlistfor a fixed set of values; - an attribute option is one allowed value of a
listdefinition (Red,Blue, …); - a product carries its values in its
attributes, each referencing adefinitionplus either anoption(forlistdefinitions) or avalue(forstringdefinitions).
-
Create a
listattribute definition.Declare a
Colorattribute whose values come from a fixed list.codeandtypeare required and, likemultiple, cannot be changed afterwards.multipledefaults totrue; set it tofalseso a product carries a single color. Capture the@id.Terminal window curl -X POST 'https://<tenant>.product-management.flowkiwi.net/api/attribute_definitions' \-H 'Authorization: Bearer {access_token}' \-H 'Flowkiwi-Api-Version: unstable' \-H 'Content-Type: application/ld+json' \-d '{"code": "color","type": "list","name": "Color","multiple": false}'{"@id": "/api/attribute_definitions/019afd10-3c4d-7e5f-8a60-2b3c4d5e6f70","@type": "AttributeDefinition","id": "019afd10-3c4d-7e5f-8a60-2b3c4d5e6f70"} -
Add its options.
Options are created under their definition. Create one per allowed value - omit
positionto append each at the end. Capture the@idof each option.Terminal window curl -X POST 'https://<tenant>.product-management.flowkiwi.net/api/attribute_definitions/019afd10-3c4d-7e5f-8a60-2b3c4d5e6f70/options' \-H 'Authorization: Bearer {access_token}' \-H 'Flowkiwi-Api-Version: unstable' \-H 'Content-Type: application/ld+json' \-d '{"value": "Red"}'{"@id": "/api/attribute_options/019afd20-5e6f-7081-8a92-4d5e6f708192","@type": "AttributeOption","id": "019afd20-5e6f-7081-8a92-4d5e6f708192"}Repeat with
"value": "Blue". Onlylistdefinitions accept options: creating one under astringdefinition is rejected with422. See Create an attribute option. -
Attach the definition to “Shoes”.
Update the category’s
attributes- the list of attribute definition IRIs attached to it. With JSON Merge Patch, the array replaces the current list, so include every definition the category should keep.Terminal window curl -X PATCH 'https://<tenant>.product-management.flowkiwi.net/api/categories/019afd02-2b3c-7d4e-9f50-1a2b3c4d5e6f' \-H 'Authorization: Bearer {access_token}' \-H 'Flowkiwi-Api-Version: unstable' \-H 'Content-Type: application/merge-patch+json' \-d '{"attributes": ["/api/attribute_definitions/019afd10-3c4d-7e5f-8a60-2b3c4d5e6f70"]}'{"@id": "/api/categories/019afd02-2b3c-7d4e-9f50-1a2b3c4d5e6f","@type": "Category","id": "019afd02-2b3c-7d4e-9f50-1a2b3c4d5e6f"}You can attach it from the other side too: a definition’s
categorieslists the categories it applies to, and can be set when you create it. See Update a category. -
Set the product’s value.
A product carries values for the definitions attached to its
category(or one of its ancestors). Set the product’scategoryto “Shoes”, and add a value to itsattributesthat references the definition and the chosen option.Terminal window curl -X PATCH 'https://<tenant>.product-management.flowkiwi.net/api/products/019af93e-420e-79f8-800b-6680f03dce20' \-H 'Authorization: Bearer {access_token}' \-H 'Flowkiwi-Api-Version: unstable' \-H 'Content-Type: application/merge-patch+json' \-d '{"category": "/api/categories/019afd02-2b3c-7d4e-9f50-1a2b3c4d5e6f","attributes": [{"definition": "/api/attribute_definitions/019afd10-3c4d-7e5f-8a60-2b3c4d5e6f70","option": "/api/attribute_options/019afd20-5e6f-7081-8a92-4d5e6f708192"}]}'{"@id": "/api/products/019af93e-420e-79f8-800b-6680f03dce20","@type": "Product","id": "019af93e-420e-79f8-800b-6680f03dce20"}attributesreplaces all of the product’s values: omit it to keep them, send[]ornullto clear them. For astringdefinition, send avalueinstead of anoption. See Update a product.
Next steps
Section titled “Next steps”- Read the tree back. List categories to see each node with its
parentandchildrens. - Read the values back. Retrieve the product with the
unstableversion: each entry of itsattributesalso mirrors the definition’scodeandtype. - Add free-text attributes. Create a
stringattribute definition - a care note, say - and set itsvalueon the product. A definition can apply to several categories at once through itscategories.