---
title: "Create a request to get search page data"
slug: "create-a-request-to-get-search-page-data"
abstract: "How to create a request to get search page data."
---
# Create a request to get search page data

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

- You want to show one result on each search result page (`n_item` = 1).

    > [!note]
    > For brevity, this example shows a request with one result per search page. You can change the value of `n_item` to, say, 12, and use the rest of the code.

- You want to make a call to get data for the first page of the search page widget (`page_number` =1).
- The user searches for the keyword *sanda*, a misspelling of sandal. You want to show the user one corrected suggestion.
- The user must be able to sort products by customer ratings.

> [!note]
> Use the [API explorer](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-search-page-widget/the-api-explorer-tab.html "The API Explorer tab") to try out requests and see sample responses.

To create a request to get search page 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-search-page-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-search-page-widget/api-authentication-and-authorization.md "API authentication and authorization") details.
2. In the request body, add [page 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-search-page-widget/page-context-object.md "Page context object") 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-search-page-widget/user-context-object.md "User context 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": "/search"
    		},
    		"user": {
    			"uuid": "sampleUUID"
    		}
    	}
    }
    ```

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

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

4. Add [pagination](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-search-page-widget/the-content-request-object.html#UUID-58f19ac5-2bfe-36e0-7790-e5e48dd687f3_section-idm4560157801720032924396739977 "Related keys") information. Specify the number of items (`n_item`) you want to see in one page of search results. Also, specify the page for which (`page_number`) you are making the call.

    ```JSON
    {
        "n_item": 1,
        "page_number": 1,
    }
    ```

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

    ```JSON
    {
    "query": {
            "keyphrase": {
                "value": [
                    "sanda"
                ]
            }
        }
    }
    ```

6. Add [suggestion](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-search-page-widget/the-suggestion-request-object.md "The suggestion request object") information to tell Discover how many suggestions you want to display if the user mistypes a keyword.

    ```JSON
    {
        "suggestion": {
            "keyphrase": {
                "max": 1
            },
        }
    }
    ```

7. Request information about the suggested keyword used if the user misspells something. To do this, use the `request_for` key. For details, see [Related key](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-search-page-widget/the-suggestion-request-object.html#UUID-368c042b-f9c5-4d17-d795-bdfde799c775_section-idm4576042353985632926028203777 "Related key")

    ```JSON
    {
        "request_for": [
            "query"
        ]
    }
    ```

    > [!note]
    > In the `request_for` response object, `orig_keyphrase` contains the original keyword and `keyphrase` is suggested by Discover.

8. Add [facet](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-search-page-widget/the-facet-request-object.md "The facet request object") information to tell Discover how many facets you want.

    ```JSON
    {
        "facet": {
            "all": true
        },
    }
    ```

9. Add [sort](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/integrating-a-search-page-widget/the-sort-request-object.md "The sort request object") information to tell Discover how you want to sort.

    ```JSON
    {
        "sort": {
            "value": [
                {
                    "name": "rating",
                    "order": "desc"
                }
            ]
        }
    }
    ```

10. 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-search-page-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-search-page-widget/sample-request-and-response-to-integrate-a-search-page-widget.html "Sample request and response to integrate a search page widget").