Adobe Commerce · updated

How do I query products and categories with Adobe Commerce GraphQL?

There are two sets of catalogue queries. On PaaS the core schema has products, which needs a search term or a filter, and categories. Catalog Service has its own products query that takes a list of SKUs, productSearch for listing and search pages, and its own categories query. Adobe Commerce as a Cloud Service supports only the service set.

In plain words

To show a product page you ask for one product by its code. To show a listing you ask for a page of products that match a search or sit in a category. Which question you send depends on which Commerce you have, because the old and new catalogue queries are not interchangeable.

Which query on which platform

NeedCore GraphQL (PaaS only)Catalog Service and Live Search
Product detail pageproducts with a filter on sku or url_keyproducts(skus: [...])
Listing or search pageproducts with search, filter, sort and pagingproductSearch
Category datacategories(filters, pageSize, currentPage)categories(ids, roles, subtree)

Core products query

  • Syntax: products(search, filter, pageSize, currentPage, sort) returns a Products object.
  • Each query must contain search, filter, or both.
  • pageSize defaults to 20 and currentPage to the first page. Asking for a page past the last one returns an error.
  • Filters Adobe lists: category_uid, description, name, price, short_description, sku and url_key.
  • sku, url_key and category filters take eq or in. Text filters take match, with match_type FULL (the default) or PARTIAL. price takes from and to.
  • Sort by name, position, price or relevance, each ASC or DESC. With search and no sort the order is relevance, descending; with only filters it is position, ascending.

Core categories query

categories(filters, pageSize, currentPage) returns pagination details and an array of category items, each with a children field for its direct subcategories. Without filters it returns the store's default root category. In the schema, the filters are category_uid, parent_category_uid, url_key, url_path and name; ids and parent_id remain but are marked deprecated. Adobe notes that a full tree cannot be returned past the queryDepth setting, 20 by default.

Catalog Service products query

products(skus: [String]) returns a list of product views. It requires one or more SKUs and is designed for product detail and compare pages. Simple, virtual, downloadable and gift card products come back as SimpleProductView with a price; all other types come back as ComplexProductView with a priceRange. Fields include sku, name, urlKey, url, inStock, description, metaTitle, metaDescription, images and attributes.

productSearch

  • phrase is required, but can be an empty string when you only filter on a category.
  • page_size defaults to 20 and current_page to 1.
  • sort is a list of attribute and direction pairs.
  • filter is a list of clauses: an attribute with eq, in, range (from and to), contains or startsWith.
  • An attribute used in a filter must be filterable in search, or Adobe says a 500 error is returned.
  • For Catalog Service, ask for items { productView { ... } }. Adobe marks the older product field as deprecated.

Catalog Service categories query

categories(ids, roles, subtree) returns category views with fields such as id, name, level, path, urlPath, urlKey, parentId and children. The subtree input takes startLevel and depth; with it, only one category ID can be given, and Adobe recommends a depth of at most 3.

Core: full text search (Adobe's sample)

{
  products(search: "Yoga pants", pageSize: 2) {
    total_count
    items {
      name
      sku
      price_range {
        minimum_price {
          regular_price {
            value
            currency
          }
        }
      }
    }
    page_info {
      page_size
      current_page
    }
  }
}

Core: one product by SKU (from Adobe's sample)

{
  products(filter: { sku: { eq: "24-MB01" } }) {
    items {
      name
      sku
    }
  }
}

Catalog Service: product details by SKU (shortened from Adobe's sample)

query {
  products(skus: ["24-UG07"]) {
    sku
    name
    urlKey
    ... on SimpleProductView {
      price {
        final { amount { value currency } }
        regular { amount { value currency } }
      }
    }
  }
}

productSearch: a listing sorted by price (shortened from Adobe's sample)

{
  productSearch(
    phrase: "bag"
    sort: [{ attribute: "price", direction: DESC }]
    page_size: 9
  ) {
    page_info { current_page page_size total_pages }
    items {
      productView { name sku }
    }
  }
}

How to write a first catalogue query

  1. Decide the platform. On Adobe Commerce as a Cloud Service, use the service queries only.
  2. Pick the query for the page type: one product, a listing, or categories.
  3. Ask only for the fields the page shows. Adobe says a query that is too complex will not run.
  4. Send the right headers: Store for core GraphQL, or the Magento-* codes for Catalog Service.
  5. Test with a small page size against a non-production environment first.

Related tools and pages on this site

Questions

Why does my products query fail on Commerce as a Cloud Service?

Because the core products query is PaaS only. Adobe says to use the Catalog Service products query there, and that applications moving from PaaS to SaaS must be updated.

Can I filter products by a custom attribute?

On core GraphQL, Adobe documents how to enable an attribute for filtering and which filter type it then takes. With productSearch, the attribute must be set as filterable in search.

How do I get the product URL?

On core GraphQL, ask for url_key (and url_rewrites if you need the rewrite list). On Catalog Service, ProductView has urlKey and url, which Adobe describes as the canonical URL of the product.

Is there a tool that writes these?

Yes. The query builder in this hub writes all five queries with the fields you tick, plus curl and fetch around them.

Sources

Facts about Adobe's products on this page are from the linked Adobe pages, read on the date shown beside each. Explanations, steps and examples are ours unless marked as Adobe's. If Adobe's page and this one differ, Adobe's page is right.

Surge Migrate is not affiliated with Adobe and claims no Adobe partner status. Adobe product names are trademarks of Adobe.

Surge Migrate

Moving the website itself

This page answers one Adobe Commerce question. Surge Migrate moves a website from any CMS to any CMS. Converted automatically. Checked before you install.

  1. 1

    Scan

    Names the system behind your site, counts pages and templates, lists the blocks to build and the work no tool does, and gives an effort range with its working.

    Scan a site →
  2. 2

    Convert

    Each page becomes an Edge Delivery document, an AEM Core Component page and import files for 7 other systems. 10 pages free; 500 or 2,000 pages in one paid run.

    Convert your pages →
  3. 3

    Verify

    A download is offered only when its own format check passes. The report lists every field not found and every component kept as plain content. Compare old and new pages side by side.

    Parity check →
  4. 4

    Install

    You import with the target system's own tool, on your own environment. Each download's README gives the command. Your system changes only when you run it.

    How each import was tested →