Lab - Brands and Categories

Plan: Developer Foundations

Lesson 10 of 21 · 45 min

This lab activity will give you a chance to practice working with brands and categories via the Catalog API. Each step will walk you through how to use all of the endpoints covered in the previous lesson.

Prerequisites:

  • BigCommerce store (sandbox or live)
  • Basic knowledge of APIs
  • REST client (Postman)
  • Completion of Catalog API labs 1 thru 3

In this lab, you will:

  • Create a brand
  • Assign a product to a brand
  • GET brands
  • Create a category
  • Update category by id
  • Assign a product to different categories
  • GET categories
  • GET category tree

The concept of category trees facilitates multi-storefront setups by allowing each storefront to have its own category hierarchy. Even in a single storefront context, however, it is still appropriate to use these API endpoints for all category operations. Where there is only a single storefront, all categories will exist in category tree ID 1.

Create a Brand

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/brands
  1. Copy and paste the code below into the Body section of Postman
{
"name": "My Brand",
"meta_keywords": [],
"custom_url": {
"url": "/brands/My-Brand"
}
}
  1. Select POST next to the request url
  2. Click the Send button
  3. Observe response and the brand created in the store
  4. Copy the brand ID for next steps

Assign a Product to a Brand

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/products/:product_id
  1. Enter the ID for the product created in the previous lab for product_id in the Params tab
  2. Copy and paste the code below into the Body section of Postman
{
"brand_id": {id}
}
  1. Replace {id} with the ID of the brand created in previous step
  2. Select PUT next to the request url
  3. Click the Send button
  4. Observe response and product assigned to new brand

GET Brands

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/brands
  1. Select GET next to the request url (if not already selected)
  2. Click the Send button
  3. Observe response

Create a Category

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/trees/categories
  1. Copy and paste the code below into the Body section of Postman
[
{
"name": "Apparel",
"url": {
"path": "/apparel/",
"is_customized": false
},
"parent_id": 0,
"tree_id": 1,
"description": "<p>A category for clothing</p>",
"sort_order": 3,
"page_title": "Apparel",
"is_visible": true
}
]
  1. Select POST next to the request url
  2. Click the Send button
  3. Observe response and category created in store
  4. Copy category ID for next steps

Update a Category

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/trees/categories
  1. Copy and paste the code below into the Body section of Postman
[
{
"category_id": {{id}},
"search_keywords":"tshirt, shirt, top"
}
]
  1. Replace {id} with the ID of the category created in the previous steps
  2. Select PUT next to the request url
  3. Click the Send button
  4. Observe response

Assign a Product to a Category

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/products/:product_id
  1. Enter the ID for the product used in previous steps for product_id in the Params tab
  2. Copy and paste the code below into the Body section of Postman
{
"categories": [
{id}
]
}
  1. Replace {id} with the ID of the category created in previous step
  2. Select PUT next to the request url
  3. Click the Send button
  4. Observe response and product assigned to new category

To add a product to a category instead of replacing its category, follow the steps above and copy the existing array over into your request. The request will look like this:

{
"categories": [
123,
456
]
}

GET Category Tree

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/trees
  1. Select GET next to the request url (if not already selected)
  2. Click the Send button
  3. Observe response