---
title: "Create a request to get preview search data"
slug: "create-a-request-to-get-preview-search-data"
abstract: "How to create a request to get preview search data."
---
# 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](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/cookies-and-personalization-information.md "Cookies and personalization information") and, if required, [authentication](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/api-authentication-and-authorization.md "API authentication and authorization") details.
2. Add [page context and user context](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/the-context-request-object.md "The context request object"). For page context, include the page `uri` and locale information (if applicable). For user context, include either the `uuid` or the `user_ID`.

    ```JSON
    {
        "context": {
            "page": {
                "uri": "/"
            },
            "user": {
                "uuid": "sampleUUID"
            }
        },
    }
    ```

3. Add [widget information](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/the-widget-request-object.md "The widget request object"). Use the `rfkid` of the preview search widget.

    ```JSON
    {
        "widget": {
            "rfkid": "rfkid_6"
        },
    }
    ```

4. Specify the [number of items](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/the-content-request-object.html#UUID-58f19ac5-2bfe-36e0-7790-e5e48dd687f3_section-idm4560157801720032924396739977 "Related keys") 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:

    ```JSON
    {
         "n_item": 3,
    }
    ```

5. Add [query information,](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/the-query-request-object.md "The query request object") that is, the keywords the user searches for.

    ```JSON
    {
        "query": {
            "keyphrase": {
                "value": [
                    "pink"
                ]
            }
        },
    }
    ```

6. Add [suggestion information](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/the-suggestion-request-object.md "The suggestion request object") to tell Discover that you want a maximum of 4 keyphrase suggestions for what the user types.

    ```JSON
    "suggestion": {
            "keyphrase": {
                "max": 4
            }
        }
    ```

7. Request [product content](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/the-content-request-object.md "The content request object"). Here, we want the entire product.

    ```JSON
    "content": {
        "product": {}
    },
    ```

You can see the complete request with all objects put together and the corresponding response in [the sample section](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-preview-search-widget/sample-request-and-response-to-integrate-a-preview-search-widget.html "Sample request and response to integrate a preview search widget").