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 setting the required filter on the line items field to specify the array containing the IDs of the two products with which you're searching the correlation:

AttributeOperator

item_ids

"in": [ "BmDzSVkXAW", "ZrxeSRgOmB" ]

Example

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":

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": {
      "line_items": {
        "item_ids": {
          "in": [ "BmDzSVkXAW", "ZrxeSRgOmB" ]
        }
      }
    }
  }'

Last updated