list-similar-products
Method: GET
Path: /catalog/products/similar
Tags: Products
Summary
Retrieve similar products
Description
Retrieves products to suggest alongside the products in product_id: their up-sell and cross-sell products or, when they have none, other products of the store; without product_id, the store's up-sell and cross-sell products. Returns only products the customer can add to the cart now: active, in stock, priced and on the customer's sales channel. A product with variants appears only as one of its variants. Only products available on this sales channel are returned.
Storefront SDK Usage
SDK Method: sdk.catalog.listSimilarProducts()
Example:
// Basic usage - get similar products for a specific product
const { data, error } = await sdk.catalog.listSimilarProducts({
product_id: ["prod_01H9XYZ12345ABCDE"]
});
// Advanced usage with pagination and custom sorting
const { data, error } = await sdk.catalog.listSimilarProducts({
product_id: ["prod_01H9XYZ12345ABCDE"],
page: 1,
limit: 20,
sort_by: '{"relevance":"desc"}'
});
// Override customer group ID for this specific request
const { data, error } = await sdk.catalog.listSimilarProducts(
{
product_id: ["prod_01H9XYZ12345ABCDE"],
page: 1,
limit: 20
},
{
"x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
}
);
if (error) {
console.error("Failed to get similar products:", error.message);
} else {
console.log("Similar products found:", data.products.length);
console.log("Pagination:", data.pagination);
data.products.forEach(product => {
console.log(`Similar: ${product.product_name} - ${product.pricing?.selling_price}`);
});
}TypeScript Definition
"list-similar-products": {
parameters: {
query?: {
/** @description Results per page. Values outside 1–100 are clamped to that range. Non-integer input returns 400. */
limit?: number;
/** @description Page number, starting at 1. Non-integer values and values below 1 return 400. */
page?: number;
/** @description to retrieve similar products of specified products */
product_id?: string[];
/** @description Sort by product fields such as `name`, `created_at`, `modified_at`, `reviews_count` or `reviews_rating_sum`, using a JSON object of field names and `asc` or `desc` values. */
sort_by?: string;
};
header?: {
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
};
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Success response */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
message: string;
success: boolean;
content: {
products: components["schemas"]["CatalogListItem"][];
pagination: components["schemas"]["Pagination"];
};
};
};
};
/** @description The request parameters or customer group are invalid. */
400: components["responses"]["BadRequest"];
401: components["responses"]["Unauthorized"];
403: components["responses"]["Forbidden"];
500: components["responses"]["InternalServerError"];
504: components["responses"]["GatewayTimeout"];
};
};Component References
| Reference | Resolves To |
|---|---|
components["parameters"]["CustomerGroupId"] | CustomerGroupId |
components["schemas"]["CatalogListItem"] | CatalogListItem |
components["schemas"]["Pagination"] | Pagination |
components["responses"]["BadRequest"] | BadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
components["responses"]["Forbidden"] | Forbidden |
components["responses"]["InternalServerError"] | InternalServerError |
components["responses"]["GatewayTimeout"] | GatewayTimeout |
Parameters
- x-customer-group-id (header): This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned.
- limit (query): Results per page. Values outside 1–100 are clamped to that range. Non-integer input returns 400.
- page (query): Page number, starting at 1. Non-integer values and values below 1 return 400.
- product_id (query): to retrieve similar products of specified products
- sort_by (query): Sort by product fields such as
name,created_at,modified_at,reviews_countorreviews_rating_sum, using a JSON object of field names andascordescvalues.
Responses
200
Success response
400
Bad request
401
Authentication failed. Codes include token-required, token-expired and token_not_valid for an invalid or expired token.
403
Access denied. token-required requires an authenticated session; permission-denied means the caller cannot access this resource. On POS, session-expired requires signing in again.
500
The request failed because of an unexpected error.
504
The request timed out.
OpenAPI Definition
{
"tags": [
"Products"
],
"operationId": "list-similar-products",
"summary": "Retrieve similar products",
"description": "Retrieves products to suggest alongside the products in `product_id`: their up-sell and cross-sell products or, when they have none, other products of the store; without `product_id`, the store's up-sell and cross-sell products. Returns only products the customer can add to the cart now: active, in stock, priced and on the customer's sales channel. A product with variants appears only as one of its variants. Only products available on this sales channel are returned.",
"externalDocs": {
"url": "https://llm-docs.commercengine.io/storefront/operations/list-similar-products",
"description": "API reference for the list-similar-products operation"
},
"parameters": [
{
"$ref": "#/components/parameters/CustomerGroupId"
},
{
"name": "limit",
"in": "query",
"description": "Results per page. Values outside 1–100 are clamped to that range. Non-integer input returns 400.",
"schema": {
"type": "integer",
"maximum": 100,
"minimum": 1
}
},
{
"name": "page",
"in": "query",
"description": "Page number, starting at 1. Non-integer values and values below 1 return 400.",
"schema": {
"type": "integer",
"minimum": 1
}
},
{
"name": "product_id",
"in": "query",
"description": "to retrieve similar products of specified products",
"schema": {
"type": "array",
"items": {
"type": "string"
}
},
"explode": false,
"style": "form"
},
{
"name": "sort_by",
"in": "query",
"description": "Sort by product fields such as `name`, `created_at`, `modified_at`, `reviews_count` or `reviews_rating_sum`, using a JSON object of field names and `asc` or `desc` values.",
"schema": {
"type": "string",
"examples": [
"{\"name\":\"asc\"}"
]
}
}
],
"responses": {
"200": {
"description": "Success response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message",
"success",
"content"
],
"properties": {
"message": {
"type": "string"
},
"success": {
"type": "boolean"
},
"content": {
"properties": {
"products": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CatalogListItem"
}
},
"pagination": {
"$ref": "#/components/schemas/Pagination"
}
},
"required": [
"products",
"pagination"
],
"type": "object"
}
}
}
}
},
"links": {
"AddItemToCart": {
"operationId": "update-cart",
"requestBody": {
"product_id": "$response.body#/content/products/0/product_id",
"variant_id": "$response.body#/content/products/0/variant_id"
},
"description": "Add a similar product to a cart."
}
}
},
"400": {
"description": "The request parameters or customer group are invalid.",
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
},
"504": {
"$ref": "#/components/responses/GatewayTimeout"
}
},
"security": [
{
"Authorization": []
},
{
"X-Api-Key": []
}
],
"x-speakeasy-group": "catalog",
"x-speakeasy-ignore": false,
"x-speakeasy-name-override": "listSimilarProducts"
}Auto-generated from OpenAPI spec and TypeScript definitions