# Search

> Ajax API endpoint for storefront search: query products by keyword and render predictive search results while the visitor is still typing.

The Search API can be used to display predictive search results for queries.

All Ajax API requests should use [locale-aware URLs](/docs/theme/references/ajax-api/#locale-aware-urls) to give visitors a consistent experience.

## Search products by keyword

```text
GET /{locale}/api/search
```

The following example requests the predictive products for a specific keyword:

```curl
GET /{locale}/api/search?keyword={query}&page={page}&limit={limit}
```

### Example request

**Example request using Fetch**

```javascript
fetch(window.SHOPLAZZA.routes.root + '/api/search?keyword=hu&page=0&limit=4')
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### Request parameters

- `keyword` string

  The search query.
- `page` number

  The base-0 page number of results.
- `limit` number

  Limits the number of results.

### Response

**Schema | Example**

- `data` object

  The response payload.

  - `cache_seconds` number

    How long the result can be cached, in seconds.
  - `filters` undefined[]

    Filters available for the results.
  - `has_more` number

    Whether more records are available.
  - `keyword` string

    Search keyword used for the query.
  - `limit` number

    Maximum number of records returned per page.
  - `page` number

    Current page number.
  - `products` undefined[]

    List of products.
  - `scm` string
  - `sort` undefined[]
  - `sorts` undefined[]

    Sort options available for the results.
  - `ssp` string
  - `total` number

    Total number of products matched.
- `msg` string

  Result message returned with the response.
- `state` number

  Request result flag; `success` or `0` means the request succeeded.

```json
{
  "data": {
    "cache_seconds": 86400,
    "filters": [],
    "has_more": 0,
    "keyword": "hu",
    "limit": 4,
    "page": 1,
    "products": [],
    "scm": "search.v39.101.102.103.104",
    "sort": [],
    "sorts": [],
    "ssp": "",
    "total": 0
  },
  "msg": "请求成功",
  "state": 0
}
```
