Lab - Complex Rules

Plan: Developer Foundations

Lesson 16 of 21 · 30 min

This lab activity will give you a chance to practice working with complex rules 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 previous Catalog API labs

In this lab, you will:

  • Create a second modifier option
  • GET modifier options
  • Create a complex rule
  • GET complex rules

Create a Second Modifier Option

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/products/:product_id/modifiers
  1. Enter the ID of the product created in previous lab for product_id in the Params tab
  2. Copy and paste the code below into the Body section of Postman
{
"type": "checkbox",
"required": false,
"config": {
"default_value": "Yes",
"checked_by_default": false,
"checkbox_label": "Check to receive a sticker"
},
"display_name": "Add an 'I Donated' sticker"
}
  1. Select POST next to the request url
  2. Click the Send button
  3. Observe response and modifier option added to product

Get Modifier Options

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/products/:product_id/modifiers
  1. Enter the ID of the product created in previous lab for product_id in the Params tab
  2. Select GET next to the request url (if not already selected)
  3. Click the Send button
  4. Observe response
  5. Copy modifier_ids and modifier_value_ids for next steps

Modifier IDs in response

Create a Complex Rule

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/products/:product_id/complex-rules
  1. Enter the ID of the product created in previous lab for product_id in the Params tab
  2. Copy and paste the code below into the Body section of Postman
{
"enabled": true,
"purchasing_disabled": true,
"purchasing_disabled_message": "You must donate before you can recieve a sticker.",
"conditions": [
{
"modifier_id": {modifier_id},
"modifier_value_id": {modifier_value_id}
},
{
"modifier_id": {modifier_id},
"modifier_value_id": {modifier_value_id}
}
]
}
  1. Replace {modifier_id} with the IDs of the checkbox modifier options: donation_checked and sticker_checked respectively
  2. Replace {modifier_value_id} with the ID of the checked modifier value to 0 and 1 respectively
  3. Select POST next to the request url
  4. Click the Send button
  5. Observe response and complex rule functioning on the product

GET Complex Rules

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/products/:product_id/complex-rules
  1. Enter the ID of the product created in previous lab for product_id in the Params tab
  2. Select GET next to the request url
  3. Click the Send button
  4. Observe response