How to work with Catalog Rules

In this article we take you through how Catalog Rules work and work with the API calls that can be used to automate the workflow.

What you’ll learn

  • The high-level Catalog Rules flow

The Catalog Rules Flow

The Concept

An operator can create catalog rules to automate validation checks for seller’s product data prior to operator review (vetting).

These catalog rules are checked when a product is saved.

Products and variants can still be saved, but they cannot progress to operator vetting until the product and at least one published variant passes these checks.

This ensures

  • Sellers get feedback quickly for any product that does not meet the validation checks.
  • Operators are only vetting products that are known to meet the validation checks, which reduces the vetting workload for operators.

APIs

Graphql changes include the following:

  • Query all catalog rules (operator or seller)
  • Query catalog rule errors on the advert type (operator or seller)
  • Query catalog rule errors on the variant type (operator or seller)

Worked Examples

The full advert creation process is described here, please refer to this for more detail.

Query Catalog Rules

query ( 
  $first: Int,
  $after: String,){

  catalogRules (
    first: $first,
    after: $after,){
    nodes {
      id
      key
      operator
      errorMessage
    }
    totalCount
    pageInfo {
      hasPreviousPage
      hasNextPage
      endCursor
      startCursor
    }
  }
}

Query Catalog Rules for an Advert Type

query($id: ID!) {
  node(id: $id) {
    ... on Advert {
      catalogRulesErrors { fieldName errorMessage objectId }
    }
  }
}

Query Catalog Rules for a Variant Type

query($id: ID!) {
  node(id: $id) {
    ... on Variant {
      catalogRulesErrors { fieldName errorMessage objectId }
    }
  }
}