Examples
The following examples provide step-by-step instructions to create a category and its structure with attributes, collections, and products. This example uses a furniture store selling lamps.
Use the following table to reference the category, subcategories, and products that will be created.
Category | Sub-Categories | Products |
---|---|---|
Lamps | ||
Ceiling Lamps | ||
Atlas Pendant Ceiling Lamp | ||
Apollo Pendant Ceiling Lamp | ||
Table Lamps | ||
Hudson Table Lamp | ||
Luminary Table Lamp |
in Product Catalog, both products and categories have attributes. Each product can have multiple attributes associated with it. Because you need to add attributes to both categories and products, the first step in building the lamps category is to create the attributes needed to fulfill our objective. In this example, lamps need to have a Style
attribute for all the products.
1. Create the Style
Attribute with the Values Modern
, Traditional
, and Rustic
The product-attributes
endpoint is used to create different product and category attributes. In this example, the Style
attribute is created for products. This attribute differentiates lamps based on design aesthetics, such as modern or rustic. In this example the type
is set to OPTIONS
since multiple accepted values are added.
Note that if you set isMandatory
to true
in the request, anything with the Style
attribute requires a value. This means if a product inherits or has the Style
attribute, it must have one of the acceptedValues
outlined in the request below.
Bash
The response includes a product attribute ID for Style
. This ID is required in subsequent API requests for mapping.
2. Create a new Lamps
Category
Use the categories
endpoint to create a new category with the name Lamps
.
Bash
After creating a category successfully, a response with the ID for the new category is returned. Use this ID to set up sub-categories.
3. Create the Ceiling Lamps
and Table Lamps
sub-categories
Use the bulk insert API for categories when you need to create more than one subcategory at a time. You must provide the parentCategoryId
that you previously received in step 2 when making the parent category Lamps
.
Optionally, you can also set isLocalizable
to true
and provide localized names.
Bash
4. Map the Style
attribute
With attribute mapping, you can update existing attributes and add new attributes to a category or product.
In this example, the product attribute ID corresponding to the Style
attribute is added to the Lamps
category, and the isMandatory
flag set to true
. With this setting, all products within the Lamps
category must have a value corresponding to the Style
attribute.
When you add an attribute to a parent category, such as Lamps
, it automatically applies to all its sub-categories. In this example, Ceiling Lamps
and Table Lamps
are children of the Lamps
category, so they inherit the mandatory Style
attribute.
For mapping, use the categories
endpoint and provide the ID corresponding to the Style
attribute that’s returned in the response from the product-attribute
endpoint.
Bash
5. Create products and variants with attributes
This example requires four products with variants, so the products status
is set to LIVE
to create variants and the parentProduct
field is included in the request body. The following code example shows adding the products using the bulk insert API for products
, which includes the mandatory attributes values:
Bash
Create a Sale
category for Modern Style Furniture
and Cyber Monday
- Create the parent collection,
Sale
.
Bash
- Create the sub category
Current Sales
. TheparentCollectionID
is returned from the previous response when creating the parent collectionSale
.
Bash
- Create the
Modern Style Furniture
andCyber Monday
categories.
Bash
Optionally, you can include products in a sale tab by filtering for specific attributes using productAttributeFilters
.
Error Handling
For effective error handling, refer to the API documentation which outlines standard HTTP error codes, such as 400 (Bad Request), 404 (Not Found), and 500 (Internal Server Error).
Next Steps
Once the above steps are completed, you are all set with the basic setup. You may proceed to fully utilize all features and capabilities available to you. Refer to the Related Resources for additional information.
Was this page helpful?