---
title: "Make a Search Configuration REST API request"
slug: "make-a-search-configuration-rest-api-request"
abstract: "How to make a Search Configuration REST API request to retrieve the configuration for your search sources."
---
# Make a Search Configuration REST API request

*Required extension points: any*

*Required SDK packages: client, xmc*

*Required API access: SitecoreAI APIs*

> [!important]
> Feature availability for the Search Configuration REST API is part of a phased rollout. Your organization may not have access to this functionality yet. It will become available when your environment is included in the rollout.

Make a request to the Search Configuration REST API request to retrieve the configuration for your SitecoreAI [search sources](https://doc.sitecore.com/xmc/en/users/xm-cloud/en/manage-content-sources.html). This configuration defines how content items are indexed and made searchable. For example, which fields you can search against, which fields you can use for filtering, and what data will be returned in search results.

> [!note]
> **Before you begin**
> -   Make sure your app is [installed](https://doc.sitecore.com/mp/en/developers/marketplace/install-an-activated-custom-app.html) in the SitecoreAI environment where you want to make API requests.
>
> -   Complete the [SDK quick start](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/quick-start--manual-.html "Quick start (manual)") and [initialize the `xmc`](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/initialize-the-xmc-package.html "Initialize the xmc package") package. In the quick start, you set up your app so it queries the application context and stores the app details in state. This is required to access the Context ID of your SitecoreAI environment when making requests to SitecoreAI APIs.

To make a Search Configuration REST API request:

1. In the `src` folder, create a component, for example, `components/SearchConfig.tsx`, then save your changes.

    ```typescript
    // src/components/SearchConfig.tsx

    import { ClientSDK } from "@sitecore-marketplace-sdk/client";

    export default function SearchConfig({
      appContext,
      client,
    }: {
      appContext: any;
      client: ClientSDK | null;
    }) {
      const getSearchConfig = async () => {
        // Get the Sitecore Context ID from the application context:
        const sitecoreContextId = appContext.resourceAccess?.[0]?.context.live;

        // Check if the Sitecore Context ID is available:
        if (!sitecoreContextId) {
          console.error(
            "Sitecore Context ID not found in application context. Make sure your app is configured to use SitecoreAI APIs."
          );
          return;
        }

        // Retrieve search configuration:
        const response = await client?.query("xmc.search.getConfigs", {
          params: {
            query: {
              sitecoreContextId,
            },
          },
        });

        console.log(response);
      };

      return <button onClick={getSearchConfig}>Retrieve Search Configuration</button>;
    }
    ```

    This script:

    - Accesses the Context ID of your SitecoreAI environment from the application context.
    - Makes a query using the Context ID: `client?.query("xmc.search.getConfigs", {<...>};`
    - Returns a button that makes the request when clicked.
2. In the SDK initialization code where you run the `useMarketplaceClient` hook, import the component you created in the previous step:

    :::tab{title="react"}
    ## React

    ```typescript
    // src/App.tsx
    import SearchConfig from "./components/SearchConfig";
    ```

    :::
    :::tab{title="nextjs-pages"}
    ## Next.js (Pages Router)

    ```typescript
    // src/pages/index.tsx
    import SearchConfig from "@/components/SearchConfig";
    ```

    :::

3. In the same file, include the component in the return statement, then save your changes. Make sure to pass `client` and the application context to the component:

    ```typescript
    return (
      <>
        {/* ... */}
        <SearchConfig appContext={appContext} client={client} />
      </>
    );
    ```

4. In the SitecoreAI Page builder, open your web browser's **Network** tab, refresh the page, then open your Marketplace app.
5. In the Marketplace app, click **Retrieve Search Configuration**.
6. On the **Network** tab, find a GET request made to `config?`. This is the request you made when you clicked the button in your app.
7. On the **Network** tab, for this request, click the **Response** tab. The API response appears.