Malachyte Portal/Recommend

Recommendations API

API reference for Malachyte Recommendations

Purpose

The Recommendations API returns a ranked list of products for a recommendation component enabled in the Malachyte Portal. It supports:

  • Component-driven behavior: the strategy, rules, filters, and ranking all come from the component in the Portal, so what shoppers see can be changed without frontend code changes.
  • Personalization and attribution: a required visitor_id (one shopper session) and an optional user_id (a logged-in shopper, across sessions) tie recommendations, clicks, and conversions together.
  • Frontend-driven execution: the client's storefront calls the API directly at runtime.

Authentication

Every request must include the API key in the request header.

HeaderTypeDescription
x-api-keystringMalachyte API key
Content-Typestringapplication/json

Base URL: https://api-yoursite.malachyte.com (the client's Malachyte contact provides the exact URL for each store).


Core Endpoints

EndpointDescription
POST /v1/recommendations/componentReturns recommended products for a given recommendation component

POST /v1/recommendations/component

Request Body Fields

FieldTypeRequiredDescription
component_idstring (UUID)YesThe ID of the recommendation component created in the Malachyte Portal. It determines the strategy, filters, and ranking logic.
querystringYesThe context for the recommendation. For product-page recommendations, this is usually the Shopify product ID. Depending on the component type, it can also be another ID, such as a collection ID.
visitor_idstring (UUID)YesIdentifier for the shopper's current session, used for personalization and attribution. Keep it the same for the whole session.
user_idstringOptionalThe unique identifier of the logged-in shopper. It stays the same across sessions. Should be left blank if the shopper isn't logged in.
kintegerOptionalThe number of recommended products to return. A default is used if it's left out.
catalogintegerOptionalThe catalog identifier. Only needed if the store has more than one catalog (for example, two storefronts or brands under one Malachyte account). Leave it out otherwise. The client's Malachyte contact provides the value.
exclusionsstring[]OptionalProduct IDs to exclude from the results.

Example Request

curl --location 'https://api-yoursite.malachyte.com/v1/recommendations/component' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"component_id": "aaa-bbb-ccc-ddd-eee",
"query": "123456",
"visitor_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"user_id": "cde456",
"k": 6
}'

Example Response

{
  "strategy_name": "recommended-for-you",
  "results": [
    {
      "score": 0.47,
      "facts": {
        "product_id": 123456,
        "name": "Classic Cotton Blazer",
        "image": "https://cdn.yourstore.com/products/classic-cotton-blazer.jpg",
        "relative_url": "/products/classic-cotton-blazer",
        "price": 120.0,
        "sale_price": 99.0
      }
    }
  ]
}
  • strategy_name: the strategy behind the component.
  • results: the recommended products, in ranked order. Each has a score and its product data in facts.
  • facts: comes from the client's product catalog, so the fields vary by store.

Error Responses

Errors return the matching HTTP status code and a JSON body with a detail message:

{
"detail": "Unknown Component: aaa-bbb-ccc-ddd-eee"
}
Status CodeDescriptionReason
400 Bad RequestUnknown componentThe component_id doesn't match a component in the Portal ("Unknown Component: <id>").
400 Bad RequestMalformed requestquery is missing ("Malformed request: query missing"), or both user_id and visitor_id are missing ("Malformed request: user_id and visitor_id missing").
404 Not FoundNo recommendations foundNo candidate products were found ("No recommendations found: No candidates returned."), or the component's filters removed all of them ("No recommendations found: All candidates filtered, try loosening filter criteria.").
422 Unprocessable EntityValidation errorA field has the wrong type.
500 Internal Server ErrorUnexpected errorAn unexpected error occurred on Malachyte's side. If it keeps happening, contact Malachyte.
503 Service UnavailableInternal errorSomething went wrong on Malachyte's side while processing the request. The request can be retried; if the error persists, contact Malachyte.

Note

A 404 means the request was valid but there were no products to recommend. The storefront should treat it as an empty result (for example, by hiding the recommendation widget) rather than as a failure.


Behavior Notes

  • Strategy ownership: everything about how results are chosen and ordered (strategy, boosts, filters, ranking) is controlled by the component_id. See Components and Rules.
  • Flexible context: the query field can represent different things depending on the component type (for example, a product ID or a collection ID).

Attribution & Identity

Tip

Data Integrity & Tracking These fields are essential for measuring recommendation performance and ROI.

  • visitor_id: a UUID that identifies the shopper's current session. It must stay the same for the whole session for personalization and attribution to work.
  • user_id: identifies a logged-in shopper and stays the same across sessions.

Testing in the Playground

A component's results can be previewed in the Portal before going live. See Playground.