Skip to content
Guides
Queries

relatedProducts

Retrieve related products from an opaque product ID.

Last updated:

relatedProducts returns visible recommendations for the specified product. The lookup prioritizes similarity and can complete the result with products from the same category, brand, or available catalog.

Signature

relatedProducts(productId: String!, limit: Int): [ProductSummary!]!

Arguments

ArgumentTypeRequiredDefaultRule
productIdString!Yes—Valid opaque product ID.
limitIntNo8Between 1 and 12.

Obtain productId from the id field returned by product or products, store it as a string, and send it back without parsing or constructing it.

If the reference product does not exist or is not visible in the store, the query returns an empty list.

Return value

The result is a non-null list of ProductSummary values:

FieldTypeDescription
idString!Opaque related product ID.
nameString!Published name.
slugString!Public slug.
productTypeString!Product type.
imageUrlString!Primary image.
priceDecimal!Current price.
compareAtPriceDecimalCompare-at price, when present.
variantCountInt!Number of variants.
isAvailableBoolean!Current availability.
totalInventoryInt!Reported total inventory.
bundleItemsCountInt!Number of bundle components.
brandString!Brand.
categoryString!Category.
statusString!Published status.
collections[String!]!Associated collections.
tags[String!]!Published tags.
sellerProductSellerInfoSeller, when present.

ProductSellerInfo contains id, name, and slug, all String!.

Query

RelatedProducts.graphql
query RelatedProducts($productId: String!, $limit: Int = 8) {
  relatedProducts(productId: $productId, limit: $limit) {
    id
    name
    slug
    productType
    imageUrl
    price
    compareAtPrice
    variantCount
    isAvailable
    totalInventory
    bundleItemsCount
    brand
    category
    status
    collections
    tags
    seller {
      id
      name
      slug
    }
  }
}

Variables:

Variables
{
  "productId": "456",
  "limit": 4
}

The example variable default matches the resolver default. You can omit limit from the variables to request up to eight results.

cURL

Terminal
curl --request POST "https://storefront.ecomiq.pe/graphql" \
  --header "Content-Type: application/json" \
  --header "x-Store-Domain: my-store" \
  --data-binary '{
    "query": "query RelatedProducts($productId: String!, $limit: Int = 8) { relatedProducts(productId: $productId, limit: $limit) { id name slug productType imageUrl price compareAtPrice variantCount isAvailable totalInventory bundleItemsCount brand category status collections tags seller { id name slug } } }",
    "variables": { "productId": "456", "limit": 4 }
  }'

Response

Response
{
  "data": {
    "relatedProducts": [
      {
        "id": "789",
        "name": "Related mug",
        "slug": "related-mug",
        "productType": "Product",
        "imageUrl": "/related.jpg",
        "price": 12,
        "compareAtPrice": null,
        "variantCount": 1,
        "isAvailable": true,
        "totalInventory": 2,
        "bundleItemsCount": 0,
        "brand": "Acme",
        "category": "Home",
        "status": "Active",
        "collections": [],
        "tags": [],
        "seller": null
      }
    ]
  }
}

Errors

CodeCommon cause
BAD_USER_INPUTproductId is not valid or limit is outside 1–12.
STORE_CONTEXT_REQUIREDx-Store-Domain did not resolve a store.

An empty list is not an error: it can mean that the reference product is not visible or no available recommendations were found. See GraphQL errors for envelope handling.

On this page