v1

latestOpenAPI 3.0.22026-08-0426137631.3 KB
Recommendation APIs

Product to Products API

The Product to Products API returns the products that are related to an anchor product (often the product the user is currently engaging with) and are also likely to drive conversions by connecting with the user’s interests. It is different from the User to Products API as it not only considers the user’s interests but also considers the recommended products' relevancy to the anchor product.

Applicable scenarios

This API is frequently used in product detail page to show related products that users can consume further, such as "Related products you may like" on Amazon or "Up next video" on Youtube. It is one of Miso's best performing APIs. Our customers usually see more than 30% and some times 110% relative lift in click-through rate after deploying this a feature using this API.

Basic usage

To use this API, you just need to let Miso knows the user_id (or anonymous_id) and the product_id you want to get related recommendations for. For example, the following request will return the products that are related to the movie Toy Story.

POST https://api.askmiso.com/v1/recommendation/product_to_products
{
    "user_id": "user_123",
    "product_id": ["toy-story-1995"],
    "rows": 3,
    "fl": ["title"]
}
  • product_id: the id of the anchor product
  • rows: the number of related products to return
  • fl: like in other Miso API, you can use fl to control which fields to return for each Product

The response will be like:

{
    "message": "success",
    "data": {
        "took": 56,
        "miso_id": "f98b1904-ddce-11eb-be53-fa1729b23183",
        "products": [
            {
                "product_id": "toy-story-2-1999",
                "title": "Toy Story 2 (1999)"
            },
            {
                "product_id": "toy-story-3-2010",
                "title": "Toy Story 3 (2010)"
            },
            {
                "product_id": "the-lion-king-1994",
                "title": "The Lion King (1994)"
            }
        ]
    }
}
  • products: a list of products related to the anchor product
  • products[ ].product_id: the id of the recommended product
  • products[ ].title: the title of the recommended product. You can use fl parameter to make Miso return more fields

Boosting and filtering

Like every Miso API, you can utilize fq and boost_fq to fine-tune the recommendations returned by Miso, and Miso will guarantee to return the required number of recommendations that meet the given criteria.

For example, the following request still recommends movies related to "Toy Story" but limits the recommendations to only the movies released after year 2010.

POST https://api.askmiso.com/v1/recommendation/product_to_products
{
    "user_id": "user_123",
    "product_id": ["toy-story-1995"],
    "rows": 3,
    "fl": ["title"],
    "fq": "custom_attributes.year: [2010 TO *]"
}

For another example, the following request will boost the movies that are acted by Tom Hanks. The boosting is different from filtering as it only prioritizes those products that match the boosting criteria and are relevant to the anchor products, but it will not limit the results to only such products.

POST https://api.askmiso.com/v1/recommendation/product_to_products
{
    "user_id": "user_123",
    "product_id": ["toy-story-1995"],
    "rows": 3,
    "fl": ["title"],
    "boost_fq": "custom_attributes.actors:\"Tom Hanks\""
}

Multiple anchor products

In the scenarios where you want to recommend products related to multiple anchor products, for example, for shopping cart cross-sell or up-sell, you can utilize product_ids parameter and have multiple product ids in it.

For instance, the following request recommends products related to movies "Toy Story" and "Monsters, Inc." that will be of interest to the the current user.

POST https://api.askmiso.com/v1/recommendation/product_to_products
{
    "user_id": "user_123",
    "product_ids": ["toy-story-1995", "monsters-inc-2001"],
    "rows": 3,
    "fl": ["title"]
}
post/v1/recommendation/product_to_products

Request body

product_idstring

The product_id of the anchor product. The returned recommendations will be the products that are similar or are liked by the same users who also like the anchor product.

product_idsstring[]

The product_ids of a list of anchor products. The returned recommendations will be the products that are similar or are liked by the same users who also like these anchor products. For example, you can use the products in a user's shopping cart as the anchor products to make purchase recommendations for this user.

product_group_idstring

The product_group_id of the anchor product group. The returned recommendations will be the products that are similar or are liked by the same users who also like the anchor product group.

You should use product_group_id on a product group page, before users select a specific product variant. For example, you should use product_group_id on the product group page of a T-shirt, and use product_id, once user choose any specific size or color variants of the T-shirt.

product_group_idsstring[]

The product_group_ids of the anchor product groups. The returned recommendations will be the products that are similar or are liked by the same users who also like the anchor product groups.

You should use product_group_ids in pages you want to recommend products related to multiple product groups.

buy_togetherboolean

Whether to focus on the Products that are frequently bought together. buy_together parameter is by default false, which make the Product To Products API focus on Products that are related to the anchor products, e.g. the products with similar contents or frequently attract the interests of the same group of users.

When buy_together=true, the ProductToProducts API will focus on the type of Products that are more frequently bought together along with the anchor product(s) in the same transactions or session.

engine_idstring

The engine you want to get results from. When you have more than one engine, you can use this parameter to specify the specific engine you want to get results from. If not specified, the default engine will be used.

user_idstring

The user who made the query and for whom Miso will personalize the results. For an anonymous visitor, use anonymous_id instead.

anonymous_idstring

The anonymous visitor who made the query and for whom Miso will personalize the results. Either user_id or anonymous_id needs to be specified for personalization to work.

user_hashstring

The hash of user_id (or anonymous_id) encrypted by your Secret API Key. user_hash is required to prevent unauthorized API access if you are making API calls with a Publishable API Key.

You should generate the user_hash via HMAC scheme: you encrypt the desired user_id (or anonymous_id) with your Secret API Key on your backend server, and then let the front-end code send the generated user_hash to Miso APIs to verify the identity of the API caller.

As long as the Secret API Key is kept secret, the user_hash prevents a malicious attacker from making unauthorized API calls or impersonating any of your users.

Miso APIs accept the case-incentive "hex digest" of user hash, a sample Python 3 code to generate it on your backend server is as follow:

import hashlib
import hmac

YOUR_MISO_SECRET_API_KEY = "039c501ac8dfcac91"
key_bytes = YOUR_MISO_SECRET_API_KEY.encode()
user_id = "USER_123" # or anonymous_id
user_id_bytes = user_id.encode()
user_hash = hmac.new(
    key_bytes,
    user_id_bytes,
    hashlib.sha256).hexdigest()
# user_hash is "7eb04da5e..."

You can find more examples for other languages in this Github Gist

user_cohortobject

The user cohort you want to cold-start the recommendation with. For example, the following query will make recommendations based on the preferences of the users whose country="United States", and gender="Female" in the User Profile dataset.

{
    "user_cohort": {
        "country": "United States",
        "gender": "Female"
    }
}
rowsinteger

Number of product recommendations to return

typestring

The type of products to return. Use this parameter to make the API return only a certain type of products (see Product APIs).

This is particularly useful for sites that have multiple types of products: For example, on a marketplace site, YOu may model merchandise and store as two types of products. You can then use type parameter to limit the recommendation or search results to return only one kind of them.

For instance, the following query will return only store products:

{"type": "store"}

For another example, on a travel website, you might have: hotel, thing to do, and restaurant, three kinds of products. You can use type parameter to limit results to one kind of them. For instance, the following query will limit the results to only hotels product:

{"type": "hotel"}
dedupe_product_group_idboolean

Whether to dedupe product based on product_group_id. If dedupe_product_group_id=true, Miso will prevent products with the same product_group_id from showing multiple times in the search or recommendation results.

This is particular useful when one product has multiple variants (for example, different sizes, colors, or materials), and you only want to show this product only once in the search or recommendation results. Miso will then return the variant that is most likely to be of the user's interest.

flstring[]

List of fields to retrieve. For example, the following request retrieves only the title field of each product along with the product_id, which is always returned.

{"fl": ["title"]}

You can also match field names by using * as a wildcard. For example, the query below retrieves the title and any custom attributes under the attributes dictionary.

{"fl": ["title", "attributes.*"]}

The following retrieves all the available fields:

{"fl": ["*"]}

For the lowest latency, use an empty array to retrieve just the product_id field (which is the default).

{"fl": []}
excludestring[]

An array of product_ids of products you want to exclude from search results.

custom_contextobject

Dictionary of custom context variables for the current browsing session. You can specify context variables specific to your websites or apps in a {"KEY":VALUE} format, where KEY must be a string, and VALUE can be:

  • a bool
  • a string or an array of string
  • a number or an array of numbers
  • an array of objects
  • null

In certain cases, Miso will take these variables into account when generating results.

boosting_tagsstring[]

When boosting_tags is given, and there are pre-defined boost rules have the same tag(s), those boost rules will be matched, regardless if the criteria is met or not.

Useful when want to force trigger specific boost campaign.

fqstring

Defines a query in Solr syntax that can be used to restrict the superset of products to return, without influencing the overall ranking. fq can enable users to drill down to products with specific features based on different product attributes

For example, the query below limits the search results to only show products whose size is either M or S and brand is Nike:

{"fq": "size:(\"M\" OR \"S\") AND brand:\"Nike\""}

You can use fq to apply filters against your custom attributes as well. For example, the query below limits the search results to only products whose designer attribute is Calvin Klein

{"fq": "attributes.designer:\"Calvin Klein\""}

fq can also limit search results by numerical range. For example, the following query limits the results to products that have rating >= 4.

{"fq": "rating:[4 TO *]"}
boost_fqstring

Defines a query in Solr syntax that can be used to boost a subset of products to the top of the ranking, or to specific boost positions (See boost_positions parameter below.) For example, the query below will promote all the relevant products whose brand is Nike to the top of recommendation list:

{
    "boost_fq": "brand:\"Nike\""
}

For a slightly more complex example, the query below will promote the Nike products which have also been tagged as ON SALE to the top of the ranking:

{
   "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\""
}

It is worth mentioning that, Miso will only boost products that are relevant and have high likelihood to convert, and will not boost a low performance product only because it matches the boosting query.

Depending on your boosting rules, in certain cases, you would like to prevent recommendation results from being too monotone due to boosting. With Miso, you have two tools to do so.

First, you can specify boost_positions to place promoted products at specific positions in the ranking. For example, the query below will place boosted products only at the first and fourth places in the ranking (positions are 0-based), and place the remaining products in their original ranking, skipping these two positions.

{
   "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"",
   "boost_positions": [0, 3]
}

The second tool is diversification. diversification parameter, on a best-effort basis, will try to maintain a minimum distance between products that have the same attributes. For example, the following query will place products made by the same brand apart from each other.

{
   "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"",
   "diversification": {
       "brand": {"minimum_distance": 1}
    }
}
boost_positionsinteger[]

Defines a list of 0-based positions you want to place the boosted products at.

For example, the query below will promote products whose brand is Nike as the top and second recommendations:

{
    "boost_fq": "brand:\"Nike\"",
    "boost_positions": [0, 1]
}

If boost_positions is not specified (which is the default behavior), all the boosted products will be ranked higher than the rest of the products.

boost_rule_namestring

Name of the boosting rule. Use this to identify a boosting rule in _boosted_rules in the response

diversificationobject

Defines diversification rules to prevent products with the same attributes (e.g. sneakers made by the same brand or books from the same authors) from showing up too close to each other in the results.

For instance, customers who have purchased many of sneakers from Nike may happen to have recommendations or search results where all top-5 entries are sneakers made by Nike. Purely considering accuracy, these recommendations appear excellent since the user clearly appreciates Nike sneakers. However, such results might be considered too "plain" by the user, owing to its lack of diversity.

diversification parameter allows you to avoid this problem by enforcing a desired minimum distance between products. For example, consider a list of four products whose brand are Nike, Nike, Adidas, and PUMA respectively. The query below will make sure there are at least one different product between two Nike products, e.g. the diversified ranking may become Nike, Adidas, Nike, and PUMA :

{
   "diversification": {"brand": {"minimum_distance": 1}}
}

You can also increase the minimum_distance to place products further apart. For example, the following query will make sure, for the two Nike products, there are at least two other products between them. As a result, the diversified ranking may become Nike, Adidas, PUMA, and Nike.:

{
   "diversification": {"brand": {"minimum_distance": 2}}
}

The diversification algorithm reranks the products on a best-effort basis. For example, for the product list described earlier, it is not possible to place two Nike product three places apart from each other. Therefore, the diversified ranking will still remain Nike, Adidas, PUMA, and Nike* even if we set minimum_distance=3.

ditheringnumber

Dithering is an optional parameter (>= 1.0, and typically <= 5.0) in the recommendation APIs that introduces randomness to the order of recommended items. By adding noise to the original ranking, it shuffles the list, surfacing lower-ranked items to enhance list freshness and potentially boost user engagement. However, excessive dithering may reduce the accuracy of item ordering. See this blog post for more information.

pagination_idstring

A unique identifier to enable pagination in Recommendation APIs. By default, Recommendation APIs do not support pagination because the results from Miso, by its natural, will change in real-time with new user interactions. pagination_id allows you to implement pagination more easily by memorize what products we have returned to the current user with the same pagination_id.

To enable pagination, you generate a pagination_id and set it in the first and subsequent requests in the same browsing session where you want to enable pagination. With pagination_id set, you can access recommendations in different pages using the combination of start and rows parameters, and Miso will ensure that no duplicated recommendation will be returned in different pages.

For example, assuming you are implementing an infinite scroll with Miso Recommendation APIs. Before you make the first request, you generate a pagination_id using the current datetime or uuid like the following:

// current datetime
var my_pagination_id = Date.now().toString()
// OR uuid
const uuidv4 = require("uuid/v4")
var my_pagination_id = uuidv4()

You can then request the first page of results with my_pagination_id like the following:

{
    "pagination_id": my_pagination_id,
    "start": 0,
    "rows": 10
}

Then, you can request the next page of results with the same my_pagination_id, and Miso will ensure that no duplicated result is returned:

{
    "pagination_id": my_pagination_id,
    "start": 10,
    "rows": 10
}

Note that, a pagination_id will timeout if there is no further request associated with it for 30 minutes. Also, pagination_id is scoped by individual users: i.e. different users' results will not be affected even if they use the same pagination_id.

startinteger

The start of the page you want to access. Combine this with rows to implement pagination. You can only set it when pagination_id is given.

Example request

{
  "additional_interactions": [
    {
      "duration": 61.5,
      "product_ids": [
        "123ABC-BLACK"
      ],
      "product_group_ids": [
        "123ABC"
      ],
      "user_id": "user_1234",
      "anonymous_id": "86D51273AD8BF84217E1567B6CBE7152D7034404",
      "miso_id": "123e4567-e89b-12d3-a456-426614174000",
      "context": {
        "campaign": {
          "name": "spring_sale",
          "source": "Google",
          "medium": "cpc",
          "term": "running+shoes",
          "content": "textlink"
        },
        "truncated_ip": "1.1.1.0",
        "locale": "en-US",
        "region": "US East",
        "page": {
          "url": "https://example.com/miso-tshirt-123ABC",
          "referrer": "https://example.com/",
          "title": "My Product Page"
        },
        "user_agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0",
        "custom_context": {
          "session_variable_1": [
            "value_1",
            "value_2"
          ]
        }
      }
    }
  ],
  "custom_context": {
    "session_variable_1": [
      "value_1",
      "value_2"
    ]
  },
  "boosting_tags": [
    "tag-1",
    "quetag-2"
  ]
}

Response

Successful Response

messagestring

Example response

{
  "data": {
    "miso_id": "123e4567-e89b-12d3-a456-426614174000",
    "products": [
      {
        "product_id": "123ABC-S-Black"
      }
    ]
  }
}