# Search API Call

1. Use - 'collection-search' endpoint for collection pages
2. Use - 'search' endpoint for search pages

## Search API

<mark style="color:blue;">`GET`</mark> `https://xyz.search.frenzy.ai/{search or collection-search}`

#### Query Parameters

| Name                 | Type    | Description                                                                                                                                                                 |
| -------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| raw\_query           | string  | User entered query.                                                                                                                                                         |
| filters              | string  | <p>Filter selected by the user<br>Format for string filter values- filter\_name:filter\_value<br><br>Format for numberial filter values-<br>filter\_name\<filter\_value</p> |
| sort                 | String  | <p>Possible values- <br>1. newest, <br>2. best match, <br>3. price asc, <br>4. price desc<br>(Default best match)</p>                                                       |
| results\_per\_page   | integer | <p>Number of results required. <br>For shopify Customers, this values is set in Portal.</p>                                                                                 |
| page\_index          | integer | Page index, starts from 0.                                                                                                                                                  |
| user\_id             | string  | User id associated with the request (only required for personalization).                                                                                                    |
| session\_id          | string  | Session id associated with the request.                                                                                                                                     |
| config\_id           | string  | Configuration id for search/collection pages.                                                                                                                               |
| ab\_test\_id         | string  | A/B test id when test is running.                                                                                                                                           |
| headless             | boolean | For headless users sent true, else false.                                                                                                                                   |
| shop                 | string  | Shopify's myshopify url. (without https\://)                                                                                                                                |
| suggestion           | string  | If the search query comes from Suggestion send true, else false.                                                                                                            |
| extra\_filters       | string  | Non UI filters to run prior finding the results.                                                                                                                            |
| collection\_id       | string  | For collection pages sent the collection id.                                                                                                                                |
| collection\_handle   | string  | For collection pages sent the collection handle.                                                                                                                            |
| currency             | string  | Currency code.                                                                                                                                                              |
| country              | string  | Country code.                                                                                                                                                               |
| state                | string  | State code.                                                                                                                                                                 |
| company\_id          | string  | Shopify B2B company id.                                                                                                                                                     |
| location\_id         | string  | Shopify B2B location id.                                                                                                                                                    |
| publication\_app\_id | string  | Shopify publication app id.                                                                                                                                                 |

#### Headers

| Name                                                     | Type   | Description                                       |
| -------------------------------------------------------- | ------ | ------------------------------------------------- |
| X-Frenzy-Authorization<mark style="color:red;">\*</mark> | string | API key provided at the time of account creation. |
| X-Shop                                                   | string | Shopify's myshopify url. (without https\://)      |

{% tabs %}
{% tab title="200 Search results successfully retrieved." %}
{% tabs %}
{% tab title="Success" %}

```javascript
{    
    "corrected_query": "red bags",
    "page_count": 15,
    "results": [
        {
            "sku":"123-123"
        },
        {
            "sku":"123-234"
        },
        {
            "sku":"123-345"
        }   
    ],
    "facet_fields": {
        
        "closure": [
            [
                "zip",
                106
            ],
            [
                "flap",
                76
            ],
            [
                "open",
                25
            ]
        ],
        "handle": [
            [
                "top handle",
                145
            ],
            [
                "leather handle",
                11
            ],
            [
                "chain handle",
                7
            ]
        ],
        
    },
    "filters": {
        "category": [
            "bags"
        ],
        "price": {
            "min": 10,
            "max": 20000
        },
        "color": [
            "red"
        ],
        "style": [
            "totes"
        ]
    },
    "products_found": 346
}
```

{% endtab %}

{% tab title="Failure" %}

```javascript
{'error': 'server_error'}
```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

### Response Object

<table data-header-hidden><thead><tr><th width="197">Key</th><th width="113.33333333333331">Type</th><th>Value</th></tr></thead><tbody><tr><td>Key</td><td>Type</td><td>Value</td></tr><tr><td>correct_query</td><td>string</td><td>Spell corrected user query by SpellCheck</td></tr><tr><td>page_count</td><td>integer</td><td>Total number of possible pages with 'results_per_page' number of products on each page.</td></tr><tr><td>results</td><td>array</td><td><a href="/pages/-MCryR4YBnNAkWIJ_Qvy">List of matching products</a></td></tr><tr><td>facet_fileds</td><td>array</td><td>Facet data for filters</td></tr><tr><td>filters</td><td>object</td><td>User-selected filters</td></tr><tr><td>products_found</td><td>integer</td><td>Total number of products found for 'raw_query'</td></tr><tr><td>request_id</td><td>string</td><td>Id for tracking the request</td></tr><tr><td>filter_order</td><td>array</td><td>Mapping for filter display name.</td></tr><tr><td>color_swatches</td><td>object</td><td>Swatches to be displayed for Filters.</td></tr></tbody></table>

### Example Request \[Collection Page]

```javascript
curl --location --request GET 'https://xyz.search.frenzy.ai/collection-search?sort=best%20match&user_id=a7d4da7c-3605-44be-9d0a-237ff0303a83&page_index=0&filters=price%3E0&filters=price%3C1000000000&filters=collections:all&headless=true'
--header 'x-frenzy-authorization: API KEY'
```

### Example Request \[Search Page]

```
curl --location --request GET 'https://xyz.search.frenzy.ai/search?sort=best%20match&user_id=a7d4da7c-3605-44be-9d0a-237ff0303a83&page_index=0&filters=price%3E0&raw_query=tops&headless=true&filters=price%3C1000000000
' \
--header 'x-frenzy-authorization: API KEY'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.frenzy.ai/api-functions/search/search-api-call.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
