---
title: "getWidgetData"
slug: "cloud-sdk-search-browser-getwidgetdata"
abstract: "The getWidgetData function retrieves data for one or more widgets. This function runs on the browser side."
---
# getWidgetData

|     |     |
| --- | --- |
| Type | Function |
| Import path | `@sitecore-cloudsdk/search/browser` |

Retrieves data for one or more widgets.

## Signature

```typescript
export async function getWidgetData(
  widgetRequestData: WidgetRequestData,
  contextRequestData?: Context
): Promise<SearchEndpointResponse | null>
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `widgetRequestData` | [`WidgetRequestData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/classes/cloud-sdk-search-widgetrequestdata.html "WidgetRequestData") | Required.<br><br>Data about the widget or widgets to retrieve. |
| `contextRequestData` | [`Context`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/classes/cloud-sdk-search-context.html "Context") | Optional.<br><br>Details about the site visitor's search request, such as locale, location, device, and web browser information. Sitecore Search uses this data for personalizing search results. |

## Return value

Returns a promise.

## Examples

:::tab{title="Next.js"}

Example 67. Running the getWidgetData function

:::tab{title="Next.js"}
> [!note]
> To run this function, you have to first [initialize](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/functions/cloud-sdk-core-browser-cloudsdk.html "CloudSDK") the Cloud SDK.

Here's an example of how to use the `getWidgetData` function to retrieve data for one widget:

```typescript
import {
  Context,
  getWidgetData,
  SearchWidgetItem,
  WidgetRequestData,
} from "@sitecore-cloudsdk/search/browser";

const context = new Context({
  language: "en",
  country: "us",
});

// Create a widget request with the entity "product" and widget ID "rfkid_7":
const searchWidget = new SearchWidgetItem("product", "rfkid_7", {
  query: {
    keyphrase: "shoes",
  },
  content: {
    fields: ["name", "price", "brand", "image_url"],
  },
  limit: 10,
});

// Call the getWidgetData function with the widget request and the context to retrieve the data:
const apiData = await getWidgetData(new WidgetRequestData([searchWidget]), context);
```

Here's an example of how to use the `getWidgetData` function to retrieve data for multiple widgets:

```typescript
import {
  Context,
  getWidgetData,
  RecommendationWidgetItem,
  SearchWidgetItem,
  WidgetRequestData,
  RecommendationWidgetItem
} from "@sitecore-cloudsdk/search/browser";

const context = new Context({
  language: "en",
  country: "us",
});

// Create a widget request with the entity "product" and widget ID "rfkid_7":
const searchWidget = new SearchWidgetItem("product", "rfkid_7", {
  query: {
    keyphrase: "shoes",
  },
  content: {
    fields: ["name", "price", "brand", "image_url"],
  },
  limit: 10,
});

// Create a second widtget request from a different type of widget (recommendation widget):
const recWidget = new RecommendationWidgetItem("product", "rfkid_2", {
  content: {
    fields: ["name", "price", "brand", "image_url"],
  },
  limit: 5,
});

// Call the getWidgetData function to get all the widget information in the same call:
const apiData = await getWidgetData(new WidgetRequestData([searchWidget, recWidget]), context);
```

:::

:::