Skip to main content

GraphQL API

Effortlessly integrate and retrieve all your Related Products data with our GraphQL API.
This API makes it simple for developers to build custom recommendations, personalized product displays, and track user interactions across headless storefronts or third-party applications.

For comprehensive information about GraphQL, refer to the GraphQL developer guide on the Magento DevDocs page.


Queries

mstRelatedBlocks

Description: returns a list of related product blocks for the specified entity (product, category, order, or customer).

Response: returns an array of mstRelatedBlock

Arguments:

NameData TypeDescription
entity_typemstSelectionEntityType!Entity type (PRODUCT, CATEGORY, ORDER, CUSTOMER)
entity_idInt!The ID of the entity
positionString(Optional) Filter by block position on the page (e.g. content.bottom)
only_activeBoolean(Optional) If true, returns only active blocks

Example:

Query:

query {
mstRelatedBlocks(
entity_type: PRODUCT,
entity_id: 123,
position: "content.bottom",
only_active: true
) {
block_id
display_title
priority
position
products {
sku
name
price_range {
minimum_price {
regular_price {
value
currency
}
}
}
}
}
}

Response:

{
"data": {
"mstRelatedBlocks": [
{
"block_id": "5",
"display_title": "You May Also Like",
"priority": 10,
"position": "content.bottom",
"products": [
{
"sku": "24-MB01",
"name": "Joust Duffle Bag",
"price_range": {
"minimum_price": {
"regular_price": {
"value": 34,
"currency": "USD"
}
}
}
}
]
}
]
}
}

mstRelatedBlock

Description: returns a single related products block by its ID.

Response: returns a mstRelatedBlock

Arguments:

NameData TypeDescription
entity_typemstSelectionEntityType!Entity type (PRODUCT, CATEGORY, ORDER, CUSTOMER)
entity_idInt!The ID of the entity
block_idInt!The ID of the related block
only_activeBoolean(Optional) If true, returns only active blocks

Example:

Query:

query {
mstRelatedBlock(
entity_type: PRODUCT,
entity_id: 123,
block_id: 5,
only_active: true
) {
block_id
display_title
position
products {
sku
name
}
}
}

Response:

{
"data": {
"mstRelatedBlock": {
"block_id": "5",
"display_title": "Cross-sell Products",
"position": "cart.crosssell",
"products": [
{
"sku": "24-WG03",
"name": "Overnight Duffle"
}
]
}
}
}

Mutations

mstRelatedTrack

Description: tracks a user interaction (click or impression) with a related block.

Response: returns a confirmation string.

Arguments:

NameData TypeDescription
typemstRelatedTrackAction!Type of interaction (CLICK or IMPRESSION)
block_idInt!Related block ID
session_idString!Unique session identifier

Example:

Mutation:

mutation {
mstRelatedTrack(
type: CLICK,
block_id: 5,
session_id: "abc123"
)
}

Response:

{
"data": {
"mstRelatedTrack": "ok"
}
}

Objects & Enums

mstRelatedBlock object

Represents a related products block.

AttributeData TypeDescription
block_idStringUnique block identifier
display_titleStringBlock title shown on storefront
priorityIntBlock priority order
positionStringPosition of the block on the page
products[ProductInterface]Array of Magento products in the block

mstSelectionEntityType enum

Defines the entity type used when requesting related products.

ValueDescription
CATEGORYRelated products based on category
CUSTOMERRelated products based on customer activity
PRODUCTRelated products for a specific product
ORDERRelated products from an order

mstRelatedTrackAction enum

Defines tracking actions for recommendation performance.

ValueDescription
CLICKTrack when a product in the block is clicked
IMPRESSIONTrack when the block is displayed (viewed)