Skip to main content

Search API

Reference for the Glood Hydrogen Search v1 surface. For a guided walkthrough, see Search & Discovery.
All search calls are v1 on the search host (https://search.glood.ai) and authenticate with Authorization: Bearer <apiKey> + x-shop. Params are camelCase (mapped to snake_case on the wire); responses are snake_case exactly as returned by the backend.

Hooks

React hooks, each usable within a <GloodProvider> whose client has the search app registered (.use(search())).

useSearch()

Runs a full product search for the current params and exposes attribution helpers.
Parametersparams is a SearchParams (all optional; query may be ""). options.skip (default false) holds fetching until required params are ready. Returns — UseSearchResult

useInstantSearch()

Type-ahead search. On an empty / too-short query the response carries trending.
Parametersparams is an InstantSearchParams (query required, may be ""). Use options.skip to gate on the minimum query length. Returns — UseInstantSearchResult

useSearchConfig()

Fetches the headless search config (feature flags, filter definitions, shop, analytics, translations, storefront token).
Returns — UseSearchConfigResult: { config: SearchConfigResponse | null, loading, error, refetch }.

useSearchInit() / useSearchInitReady()

GloodProvider runs the search session bootstrap once on mount (when search() is registered), mirroring recs init. You don’t call it yourself — these hooks read its result:
  • useSearchInit() returns the SearchInitResponse (visitor identity, history, lean config, token, visit_id), or null until it resolves.
  • useSearchInitReady() returns true once init has settled (success or failure). useSearch and useInstantSearch gate their fetches on this, so they don’t fire before the session is bootstrapped.

Standalone functions

Isomorphic functions for the v1 search suite. Use them in Hydrogen route loaders (SSR) or anywhere you need the API without a React component. Every function takes options: FetchSearchOptions as its first argument.

Endpoints

Each function POSTs to a path under the search endpoint (default https://search.glood.ai), all v1:
FetchSearchOptions is the shared HeadlessRequestOptionsapiKey and myShopifyDomain are required; endpoint (default https://search.glood.ai) and debug are optional. The version is pinned to 1 internally. In the browser, visitor_id / client_id / session_id default from the Glood cookies when omitted.
The standalone functions above POST to whatever endpoint you pass in options. When you call through the SearchApp (app.imageSearch(...), the track* helpers, auto-subscribed events), routing is split automatically: imageSearch and all events go to the app’s controlEndpoint (non-edge), while every other call uses endpoint. See Configuration → Edge vs. non-edge routing.

fetchSearchInit()

Session bootstrap — resolves the visitor, returns their history (browsed / cart / purchased product ids), a lean feature-flag config (no filter definitions, no filter tree), the storefront token and a fresh visit_id. GloodProvider runs this automatically on mount; call it directly only for SSR or non-React use.

fetchSearchConfig()

fetchInstantSearch()

query is required (may be ""); throws locally if query is undefined/null.

fetchFilters()

fetchFilterAggregations()

fetchSearchResults()

fetchImageSearch()

Exactly one of image / imageUrl is required (throws locally otherwise).

sendSearchEvent()

The v1 analogue of sendHeadlessEvent. In the browser, channel ('hydrogen'), session_id, client_id and visitor_id are filled from cookies when omitted. Extra snake_case fields (cart, customer, customer_privacy, …) pass through. For SSR / non-React use; inside React prefer the SearchApp track helpers wired up by GloodProvider.
event.timestamp must be an ISO 8601 string within ±2 days of now (server rule). The events API requires at least one of visitor_id / client_id (defaulted from cookies in the browser).

Errors — GloodApiError

Thrown by every standalone function on a non-2xx response (re-exported from the search module):

SearchApp

The app instance registered via client.use(search()). Retrieve it from the client for advanced / SSR usage:

Methods

Event helpers

Each emits a glood:search:* custom event via the pixel pipeline and returns void:
Track events respect the app’s pixel config: if pixel.enabled is false, they are not sent.

search() module

Factory that creates and configures the search app. Pass { events } to narrow the standard Shopify events forwarded to the search backend (default: all events).

SearchTrack object

Attribution payload for glood:search:* events (snake_case wire shape):

Response shapes

The key response types (SearchResponse, InstantSearchResponse, SearchConfigResponse, FiltersResponse, FilterAggregationsResponse, ImageSearchResponse) and the shared SearchProduct object are documented in full in TypeScript Types → Search API Types.

Example — SearchResponse

See Also