--- title: Predictive Search API reference description: >- Learn about the requests that the Predictive Search API can make and the responses it will return. api_name: ajax source_url: html: 'https://shopify.dev/docs/api/ajax/reference/predictive-search' md: 'https://shopify.dev/docs/api/ajax/reference/predictive-search.md' --- ExpandOn this page * [GET /{locale}/search/suggest.json](https://shopify.dev/docs/api/ajax/reference/predictive-search.md#get--locale-search-suggestjson) * [GET /{locale}/search/suggest](https://shopify.dev/docs/api/ajax/reference/predictive-search.md#get--locale-search-suggest) * [Searchable properties](https://shopify.dev/docs/api/ajax/reference/predictive-search.md#searchable-properties) * [Typo tolerance](https://shopify.dev/docs/api/ajax/reference/predictive-search.md#typo-tolerance) * [Requirements and limitations](https://shopify.dev/docs/api/ajax/reference/predictive-search.md#requirements-and-limitations) # Predictive Search API reference The Predictive Search API can be used to display predictive search results for queries, products, collections, pages, and articles. To learn how to use predictive search in a theme, refer to [Add predictive search to your theme](https://shopify.dev/docs/storefronts/themes/navigation-search/search/predictive-search). All Ajax API requests should use [locale-aware URLs](https://shopify.dev/docs/api/ajax#locale-aware-urls) to give visitors a consistent experience. *** ## GET /{locale}/search/suggest.json The following example request retrieves predictive results for a specified search query: ```js GET /{locale}/search/suggest.json?q={query} ``` ### Query parameters | Query parameter | Required | Description | | - | - | - | | `q` | Yes | The search query. | | `resources[type]` | No | Specifies the type of results requested.The following are the accepted values, which can be combined in a comma-separated list:- `product` - `page` - `article` - `collection` - `query`The default value is `query,product,collection,page`.To change the default value, you can use [Search Settings](https://help.shopify.com/manual/online-store/search-and-discovery/settings) in the Search & Discovery app. | | `resources[limit]` | No | Limits the number of results based on `limit_scope`.The value can range from `1` to `10`, and the default is `10`. | | `resources[limit_scope]` | No | Decides the distribution of results.The following are the accepted values:- `all`: Return results up to `limit` across all types. - `each`: Return results up to `limit` per type.The default value is `all`. | | `resources[options][unavailable_products]` | No | Specifies whether to display results for unavailable products.The following are the accepted values:- `show`: Show unavailable products. - `hide`: Hide unavailable products. - `last`: Show unavailable products below other matching results.The default value is `last`.To change the default value, you can use [Search Settings](https://help.shopify.com/manual/online-store/search-and-discovery/settings) in the Search & Discovery app.This parameter is only applicable to type `product`. | | `resources[options][fields]` | No | Specifies the list of resource fields to search.The following are the accepted values:- `author` - `body` - `product_type` - `tag` - `title` - `variants.barcode` - `variants.sku` - `variants.title` - `vendor`The default fields searched on are `title`, `product_type`, `variants.title`, and `vendor`. For the best search experience, you should search on the default field set. | ## Example request object ```json { "q": "bag", "resources": { "type": "product", "options": { "unavailable_products": "hide", "fields": "title,product_type,variants.title" } } } ``` ## Example request using Fetch ```javascript fetch(window.Shopify.routes.root + "search/suggest.json?q=bag&resources[type]=product&resources[options][unavailable_products]=hide&resources[options][fields]=title,product_type,variants.title") .then((response) => response.json()) .then((suggestions) => { const productSuggestions = suggestions.resources.results.products; if (productSuggestions.length > 0) { const firstProductSuggestion = productSuggestions[0]; alert(`The title of the first product suggestion is: ${ firstProductSuggestion.title}` ); } } ); ``` ### Resources response The following example is a response to a successful request to the `/{locale}/search/suggest.json` endpoint, which contains resource objects associated with the specified query: ## Example resources response ```json { "resources": { "results": { "queries" : ARRAY OF RELEVANT search queries, "products": ARRAY OF MATCHING product_object, "collections": ARRAY OF MATCHING collection_object, "pages": ARRAY OF MATCHING page_object, "articles": ARRAY OF MATCHING article_object } } } ``` Caution You shouldn't output the `body` content of resource objects for stores that support multiple languages. When a store supports multiple languages, the `body` content contains a combination of the content translated in each language. ## Example product\_object ```json { "available": BOOLEAN, "body": STRING w/HTML, "compare_at_price_max": DECIMAL ("0.00" when the product has no variants with a "compare_at_price"), "compare_at_price_min": DECIMAL ("0.00" when the product has no variants with a "compare_at_price"), "handle": STRING, "id": INTEGER, "image": STRING e.g, "https://cdn.shopify.com/s/...", "price": DECIMAL, "price_max": DECIMAL, "price_min": DECIMAL, "tags" : ARRAY OF STRING, "title": STRING, "type" : STRING, "url": STRING e.g, "/products/fast-snowboard?_pos=1&_psq=snowb&_ss=e&_v=1.0", "variants": [{ "available": BOOLEAN, "compare_at_price": DECIMAL (nullable), "id": INTEGER, "image": STRING e.g, "https://cdn.shopify.com/s/...", "price": DECIMAL, "title": STRING, "url": STRING e.g, "/products/fast-snowboard?_pos=1&_psq=snowb&_ss=e&_v=1.0", "featured_image": { "alt": STRING, "aspect_ratio": DECIMAL, "height": INTEGER, "url": STRING e.g, "https://cdn.shopify.com/s/...", "width": INTEGER } }], "vendor": STRING, "featured_image": { "alt": STRING, "aspect_ratio": DECIMAL, "height": INTEGER, "url": STRING e.g, "https://cdn.shopify.com/s/...", "width": INTEGER } } ``` Note A product variant is returned only when the query matches terms specific to the variant title. Only the variant with the most matching terms is returned. When a variant is returned, the following `product_object` fields will match those of the variant: * `featured_image` * `image` * `url` For example, a store has a snowboard with a blue variant and a light blue variant. If you search for `snowbo`, then only the snowboard product is returned. However, if you search for `light blue snowbo`, then the snowboard product is returned with the light blue variant. ## Example collection\_object ```json { "body": STRING w/HTML, "handle": STRING, "id": INTEGER, "featured_image": { "alt": STRING, "width": INTEGER, "height": INTEGER, "aspect_ratio": DECIMAL, "url": STRING e.g, "https://cdn.shopify.com/s/..." }, "published_at": STRING DATE, "title": STRING, "url": STRING e.g, "/collections/snowboards?_pos=1&_psq=sno&_ss=e&_v=1.0" } ``` ## Example query\_object ```json { "url": STRING e.g, "/search?_pos=1&_psq=cos&_ss=e&_v=1.0&q=costume", "text":STRING, "styled_text": STRING e.g, "costume" } ``` ## Example page\_object ```json { "author": STRING, "body": STRING w/HTML, "handle":STRING, "id": INTEGER, "published_at": STRING DATE, "title": STRING, "url": STRING e.g, "/pages/my-page?_pos=1&_psq=my&_ss=e&_v=1.0" } ``` ## Example article\_object ```json { "author": STRING, "body": STRING w/HTML, "handle": STRING, "id": INTEGER, "image": STRING e.g, "https://cdn.shopify.com/s/...", "published_at": STRING DATE, "summary_html": STRING w/HTML, "tags": ARRAY OF STRING, "title": STRING, "url": STRING e.g, "/blogs/news/my-article?_pos=1&_psq=my&_ss=e&_v=1.0" } ``` ### Error responses When a request to the `/{locale}/search/suggest.json` endpoint is unsuccessful, one of the following error responses is returned: * [Invalid parameter error](#invalid-parameter-error) * [Expectation failed](#expectation-failed) * [Too many requests](#too-many-requests) Any other errors not listed will return a `5xx` status code. #### Invalid parameter error All errors related to the request parameters are returned with a 422 status code and a relevant error message. The `description` field describes the request error. ## Invalid parameter example ```json { "status": "422", "message": "Invalid parameter error", "description": "Invalid option for `unavailable_products` parameter" } ``` #### Expectation failed If your theme isn't using one of the [supported languages](#supported-languages), then the API returns the following error: ## Expectation failed example ```json { "status": "417", "message": "Expectation Failed", "description": "Unsupported buyer locale" } ``` #### Too many requests Exceeding the request throttle limit will return a 429 status code with a relevant error message. ## Example ```json { "status": "429", "message": "Too many requests", "description": "Throttled" } ``` In this case, the response will also contain an HTTP header with the Retry-After value in seconds. ## Retry-After example ```text Retry-After: 1 ``` *** ## GET /{locale}/search/suggest The following example request retrieves the HTML from a section rendered with the predictive results for a specified search query. ```js GET /{locale}/search/suggest?q={query}&resources[type]=product§ion_id={section_id} ``` ### Query parameters The `/search/suggest` endpoint supports the same [query parameters](https://shopify.dev/docs/api/ajax/reference/predictive-search#query-parameters) as the `/search/suggest.json` endpoint, in addition to the following: | Query parameter | Required | Description | | - | - | - | | `section_id` | Yes | The unique [section ID](https://shopify.dev/docs/api/ajax/section-rendering#find-section-ids) of the section file that you want render with the predictive search query. | ## Example request object ```json { "q": "bag", "resources": { "type": "product", "options": { "unavailable_products": "hide", "fields": "title, product_type, variants.title" } }, "section_id": "predictive-search" } ``` ## Example request using Fetch ```javascript const predictiveSearchSection = document.querySelector('.predictive-search-results'); var requestResponse; fetch(window.Shopify.routes.root + "search/suggest?q=bag&resources[type]=product&resources[options][unavailable_products]=hide&resources[options][fields]=title,product_type,variants.title§ion_id=predictive-search") .then((response) => { requestResponse = response; return response.text(); }) .then((text) => { if (!requestResponse.ok) { throw new Error(`${requestResponse.status}: ${text}`); } const resultsMarkup = new DOMParser() .parseFromString(text, 'text/html') .querySelector('#shopify-section-predictive-search').innerHTML; predictiveSearchSection.innerHTML = resultsMarkup; }) .catch((error) => { console.error(error); }); ``` ### Section response The response to a successful request to the `/{locale}/search/suggest` endpoint. The section response contains the HTML of the provided section rendered with the [`predictive_search` object](https://shopify.dev/docs/api/liquid/objects/predictive_search) containing the results of the specified query. For example, the following section would generate the following section response: ## Example section ```liquid {%- if predictive_search.performed -%}