> This page is for Developer.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bigcommerce.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bigcommerce.com/_mcp/server.

# Code Samples for Promotions that Use Logical Operators

## Buy two of product X or buy two of product Y (OR operator)

The following promotion uses the logical `OR` operator at item matcher level. Each of the following combinations satisfies the condition:

* 1 product X + 1 product Y
* 2 product X
* 2 product Y

#### Request

**`Example request`**

```json title="Example request"
{
  "name": "Buy two of product X or buy two of product Y",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "condition": {
        "cart": {
          "items": {
            "or": [
              {
                "products": [
                  118
                ]
              },
              {
                "variants": [
                  134
                ]
              }
            ]
          },
          "minimum_quantity": 2
        }
      },
      "action": {
        "gift_item": {
          "product_id": 130,
          "quantity": 1
        }
      }
    }
  ],
  "notifications": [
    {
      "type": "UPSELL",
      "content": "<div>&nbsp;</div>",
      "locations": [
        "CART_PAGE"
      ]
    },
    {
      "type": "ELIGIBLE",
      "content": "<div>&nbsp;</div>",
      "locations": [
        "CART_PAGE"
      ]
    },
    {
      "type": "APPLIED",
      "content": "<div>&nbsp;</div>",
      "locations": [
        "CART_PAGE"
      ]
    }
  ],
  "stop": false,
  "start_date": "2019-02-01T05:00:00+00:00",
  "status": "ENABLED"
}
```

#### Response

**`Example response`**

```json title="Example response"
{
  "data": {
    "id": 47,
    "name": "Buy two of product X or buy two of product Y",
    "created_from": "api",
    "customer": {
      "group_ids": [],
      "minimum_order_count": 0,
      "excluded_group_ids": [],
      "segments": null
    },
    "rules": [
      {
        "action": {
          "gift_item": {
            "quantity": 1,
            "product_id": 130
          }
        },
        "apply_once": true,
        "stop": false,
        "condition": {
          "cart": {
            "items": {
              "or": [
                {
                  "products": [
                    118
                  ]
                },
                {
                  "variants": [
                    134
                  ]
                }
              ]
            },
            "minimum_quantity": 2
          }
        }
      }
    ],
    "notifications": [
      {
        "type": "UPSELL",
        "content": "<div>&nbsp;</div>",
        "locations": [
          "CART_PAGE"
        ]
      },
      {
        "type": "ELIGIBLE",
        "content": "<div>&nbsp;</div>",
        "locations": [
          "CART_PAGE"
        ]
      },
      {
        "type": "APPLIED",
        "content": "<div>&nbsp;</div>",
        "locations": [
          "CART_PAGE"
        ]
      }
    ],
    "stop": false,
    "currency_code": "USD",
    "redemption_type": "AUTOMATIC",
    "shipping_address": null,
    "current_uses": 0,
    "max_uses": null,
    "start_date": "2019-02-01T05:00:00+00:00",
    "end_date": null,
    "status": "ENABLED",
    "schedule": null,
    "can_be_used_with_other_promotions": true
  },
  "meta": {}
}
```

## Get percentage off X category, excluding an item (AND, NOT operators)

#### Request

**`Example request`**

```json title="Example request"
{
  "name": "Get 20% off all kitchen items, excluding Able Brewing System",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "action": {
        "cart_items": {
          "items": {
            "and": [
              {
                "categories": [
                  25
                ]
              },
              {
                "not": {
                  "products": [
                    129
                  ]
                }
              }
            ]
          },
          "discount": {
            "percentage_amount": "20"
          }
        }
      },
      "apply_once": true
    }
  ]
}
```

#### Response

**`Example response`**

```json title="Example response"
{
  "data": {
    "id": 23,
    "name": "Get 20% off all kitchen items, excluding Able Brewing System",
    "created_from": "api",
    "customer": {
      "group_ids": [],
      "minimum_order_count": 0,
      "excluded_group_ids": [],
      "segments": null
    },
    "rules": [
      {
        "action": {
          "cart_items": {
            "discount": {
              "percentage_amount": "20"
            },
            "strategy": "LEAST_EXPENSIVE",
            "add_free_item": true,
            "as_total": false,
            "include_items_considered_by_condition": false,
            "exclude_items_on_sale": false,
            "items": {
              "and": [
                {
                  "categories": [
                    25
                  ]
                },
                {
                  "not": {
                    "products": [
                      129
                    ]
                  }
                }
              ]
            }
          }
        },
        "apply_once": true,
        "stop": false
      }
    ],
    "notifications": [],
    "stop": false,
    "currency_code": "USD",
    "redemption_type": "AUTOMATIC",
    "shipping_address": null,
    "current_uses": 0,
    "max_uses": null,
    "start_date": "2022-07-21T14:00:11+00:00",
    "end_date": null,
    "status": "ENABLED",
    "schedule": null,
    "can_be_used_with_other_promotions": true
  },
  "meta": {}
}
```

## Get X% off all brand X, except X products in brand Y (OR, AND, NOT operators)

#### Request

**`Example request`**

```json title="Example request"
{
  "name": "Get 20% off all coffee makers except for those using new arrivals coffee filters",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "action": {
        "cart_items": {
          "items": {
            "or": [
              {
                "and": [
                  {
                    "brands": [
                      37
                    ]
                  },
                  {
                    "categories": [
                      25
                    ]
                  }
                ]
              },
              {
                "and": [
                  {
                    "brands": [
                      38
                    ]
                  },
                  {
                    "categories": [
                      35
                    ]
                  },
                  {
                    "not": {
                      "categories": [
                        24
                      ]
                    }
                  }
                ]
              }
            ]
          },
          "discount": {
            "percentage_amount": "20"
          }
        }
      },
      "apply_once": true,
      "currency_code": "AUD"
    }
  ]
}
```

#### Response

**`Example response`**

```json title="Example response"
{
  "data": {
    "id": 22,
    "name": "Get 20% off all coffee makers except for those using new arrivals coffee filters",
    "created_from": "api",
    "customer": {
      "group_ids": [],
      "minimum_order_count": 0,
      "excluded_group_ids": [],
      "segments": null
    },
    "rules": [
      {
        "action": {
          "cart_items": {
            "discount": {
              "percentage_amount": "20"
            },
            "strategy": "LEAST_EXPENSIVE",
            "add_free_item": true,
            "as_total": false,
            "include_items_considered_by_condition": false,
            "exclude_items_on_sale": false,
            "items": {
              "or": [
                {
                  "and": [
                    {
                      "brands": [
                        37
                      ]
                    },
                    {
                      "categories": [
                        25
                      ]
                    }
                  ]
                },
                {
                  "and": [
                    {
                      "brands": [
                        38
                      ]
                    },
                    {
                      "categories": [
                        35
                      ]
                    },
                    {
                      "not": {
                        "categories": [
                          24
                        ]
                      }
                    }
                  ]
                }
              ]
            }
          }
        },
        "apply_once": true,
        "stop": false
      }
    ],
    "notifications": [],
    "stop": false,
    "currency_code": "USD",
    "redemption_type": "AUTOMATIC",
    "shipping_address": null,
    "current_uses": 0,
    "max_uses": null,
    "start_date": "2022-07-21T13:55:35+00:00",
    "end_date": null,
    "status": "ENABLED",
    "schedule": null,
    "can_be_used_with_other_promotions": true
  },
  "meta": {}
}
```

## X% off storewide except product Y or product Z or any items in category C

#### Request

**`Example request`**

```json title="Example request"
{
  "name": "10% off storewide except 'Able Brewing System' or 'Chemex Coffeemaker' or any garden products",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "action": {
        "cart_items": {
          "discount": {
            "percentage_amount": 10
          },
          "items": {
            "and": [
              {
                "not": {
                  "products": [
                    129,
                    130                 ]
                }
              },
              {
                "not": {
                  "categories": [
                    24
                  ]
                }
              }
            ]
          }
        }
      },
      "apply_once": true
    }
  ]
}
```

#### Response

**`Example response`**

```json title="Example response"
{
  "data": {
    "id": 21,
    "name": "10% off storewide except 'Able Brewing System' or 'Chemex Coffeemaker' or any garden products",
    "created_from": "api",
    "customer": {
        "group_ids": [],
        "minimum_order_count": 0,
        "excluded_group_ids": [],
        "segments": null
    },
    "rules": [
      {
        "action": {
          "cart_items": {
            "discount": {
                "percentage_amount": "10"
            },
            "strategy": "LEAST_EXPENSIVE",
            "add_free_item": true,
            "as_total": false,
            "include_items_considered_by_condition": false,
            "exclude_items_on_sale": false,
            "items": {
              "and": [
                {
                  "not": {
                    "products": [
                      129,
                      130
                    ]
                  }
                },
                {
                  "not": {
                    "categories": [
                      24
                    ]
                  }
                }
              ]
            }
          }
        },
        "apply_once": true,
        "stop": false
      }
    ],
    "notifications": [],
    "stop": false,
    "currency_code": "USD",
    "redemption_type": "AUTOMATIC",
    "shipping_address": null,
    "current_uses": 0,
    "max_uses": null,
    "start_date": "2022-07-21T13:49:42+00:00",
    "end_date": null,
    "status": "ENABLED",
    "schedule": null,
    "can_be_used_with_other_promotions": true
  },
  "meta": {}
}
```