FBT

How to perform an FBT query and how it works

Request

To perform an FBT query send a POST request to the /analysis/fbt endpoint specifying the item ID(s) in the filter without any extra query keys:

{
  "filter": {
    "line_items": {
      "item_ids": {
        "in": [
          "...",
          "..."

          // ...

        ]
      }
    }
  },
  "meta": { ... }
}

Please note that while the attribute value of the in operator used in the standard filters matches any (logic OR) of the specified array's values, the attribute value of the in operator used in the FBT filters matches all (logic AND) of the specified array's values.

The filter object is required (if missing the API will respond with a 400 Bad request error). You can optionally add the meta object for any useful information about the query itself (learn more here).

Response

The response of an FBT query returns an aggregation by item ID ordered by value (e.g. from the most frequently bought together item to the less frequently bought together item), with some additional information:

{
  "data": [
    {
      "item_id": "...",
      "value": ...,
      "type": "...",
      "name": "..."
    },
    { ... }
  ],
  "meta": { ... }
}

The FBT query returns a maximum of 10 records (i.e. the 10 most frequently bought together items).

Example

The following request performs an FBT query to get the items most frequently bought together with the item identified by the ID "BmDzSVkXAW":

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" ]
        }
      }
    }
  }'

Last updated