Create a request to get preview search data

This topic shows you how to make a call to the Sitecore Discover Search and Recommendation API to get a preview search widget in the following scenario:

  • The user enters the keyphrase pink in the search field.

  • You want to show 3 product suggestions in the search results area (n_item=3).

  • You want to show a maximum of 4 keyphrase suggestions in the autocomplete area.

To create a request to get preview search data:

  1. In the header, add cookies and, if required, authentication details.

  2. Add page context and user context. For page context, include the page uri and locale information (if applicable). For user context, include either the uuid or the user_ID.

    RequestResponse
    {
        "context": {
            "page": {
                "uri": "/"
            },
            "user": {
                "uuid": "sampleUUID"
            }
        },
    }
  3. Add widget information. Use the rfkid of the preview search widget.

    RequestResponse
    {
        "widget": {
            "rfkid": "rfkid_6"
        },
    }
  4. Specify the number of items you want to see in the preview search results.

    Note

    You do not have to specify the page number in your request because preview search results usually do not have more than one page.

    Here is an example:

    RequestResponse
    { 
         "n_item": 3,
    }
    
  5. Add query information, that is, the keywords the user searches for.

    RequestResponse
    {
        "query": {
            "keyphrase": {
                "value": [
                    "pink"
                ]
            }
        },
    }
  6. Add suggestion information to tell Discover that you want a maximum of 4 keyphrase suggestions for what the user types.

    RequestResponse
        "suggestion": {
            "keyphrase": {
                "max": 4
            }
        }
  7. Request product content. Here, we want the entire product.

    RequestResponse
    "content": {
        "product": {}
    },

You can see the complete request with all objects put together and the corresponding response in the sample section.

Do you have some feedback for us?

If you have suggestions for improving this article,