> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/metrics/getting-started/use-cases/frequently-bought-together-products.md).

# Frequently bought together products

How to use the Metrics API to get the products that have been most frequently bought together with other ones

### The problem

You want to get the list of products that, over your order history, have been added as line items to the same orders as two specific other products (SKUs or bundles).

### The solution

#### Filter

You need to perform an [FBT query](/metrics/getting-started/analysis/fbt.md) setting the required filter on the [line items](/metrics-api-reference/resources/orders/filters.md#line_items-field) field to specify the array containing the IDs of the two products with which you're searching the correlation:

<table><thead><tr><th width="359">Attribute</th><th>Operator</th></tr></thead><tbody><tr><td><strong><code>item_ids</code></strong></td><td><code>"in": [ "BmDzSVkXAW", "ZrxeSRgOmB" ]</code></td></tr></tbody></table>

### [Try it on Postman](https://www.postman.com/commercelayer/workspace/commerce-layer-public-workspace/documentation/19711194-37a2d863-72f6-4b8f-8146-2f61d405fd3c?entity=request-19711194-5c703670-609a-4c25-939a-1212bf66a1dd) :rocket:

### Example

{% tabs %}
{% tab title="Request" %}
The following request uses the Metrics API to get the list of products that have been most frequently bought together with the items identified by the IDs "BmDzSVkXAW" and "ZrxeSRgOmB":

<pre class="language-shell"><code class="lang-shell">curl -g -X POST \
  'https://{{your_domain}}.commercelayer.io/metrics/analysis/fbt' \
  -H 'Accept: application/vnd.api.v1+json' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'Authorization: Bearer {{your_access_token}}' \
  -d '{
    "filter": {
<strong>      "line_items": {
</strong><strong>        "item_ids": {
</strong><strong>          "in": [ "BmDzSVkXAW", "ZrxeSRgOmB" ]
</strong><strong>        }
</strong><strong>      }
</strong>    }
  }'
</code></pre>

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the aggregated values in the `data` object and additional information in the `meta` object:

<pre class="language-json"><code class="lang-json">{
  "data": [
    {
<strong>      "item_id": "nprzSARKeW",
</strong><strong>      "value": 103,
</strong>      "type": "skus",
      "name": "Black T-Shirt, Men, Size L"
    },
    {
<strong>      "item_id": "ZNRJSQXkjZ",
</strong><strong>      "value": 99,
</strong>      "type": "skus",
      "name": "Pink T-Shirt, Women, Size XXS"
    },
    {
<strong>      "item_id": "BxAkSrDODn",
</strong><strong>      "value": 41,
</strong>      "type": "skus",
      "name": "Pink Short Pants, Women, Size XS"
    },
    { ... }
  ],
  "meta": {
    "type": "fbt",
    "trace_id": "fe571ea2-8a4f-4a5e-bd26-ac54651bb2e4",
    "mode": "test",
    "organization_id": "xYZkjABcde",
    "market_ids": [ "yzXKjYzaCx", "..." ]
  }
}
</code></pre>

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.commercelayer.io/metrics/getting-started/use-cases/frequently-bought-together-products.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
