> ## Documentation Index
> Fetch the complete documentation index at: https://docs.glood.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Headless Search Init

> Session bootstrap for the search suite. Call once per session (the `@glood/hydrogen` GloodProvider runs it automatically on mount) before instant/full search. Resolves the visitor, returns their history (browsed / cart / purchased product ids), a lean feature-flag config (no filter definitions, no filter tree, no templates), the Shopify storefront token and a fresh `visit_id`. Auth: `Authorization: Bearer <gl_sf_...>` + `x-shop`.

```json 200 theme={null}
{
  "visit_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "visitor_id": "gl_s_uid_9f2c",
  "client_id": "c_18a4",
  "customer_id": null,
  "visitor": {
    "browsed_products": [9311227838783, 9311227838784],
    "cart_products": [9311227838785],
    "purchased_products": []
  },
  "config": {
    "instant_search_enabled": true,
    "search_result_page_enabled": true,
    "image_search_enabled": true,
    "personalization_enabled": false,
    "personalization_config": null,
    "auto_spell_correct_enabled": true,
    "instant_search_objects": ["product", "collection", "page", "auto_suggestion"],
    "exclude_out_of_stock": false,
    "move_out_of_stock_at_end": true,
    "site_wide_search": {},
    "search_result_count": 10,
    "default_ordering": "relevance",
    "minimum_type_ahead_input_count": 2,
    "default_search_result_page_size": 20,
    "search_page_autocomplete_enabled": true,
    "search_page_handle": "search",
    "image_search_pages": null,
    "settings": {}
  },
  "token": "shpat_xxx",
  "metadata": { "region": "toronto", "locale": "en-US", "market": null }
}
```

```json 400 theme={null}
{
  "error": [
    {
      "message": "\"page_type\" must be one of [product_page, collection, home, cart, order_confirm, blog, ajax_cart, 404, checkout, returns, search, other]",
      "path": ["page_type"],
      "type": "any.only",
      "context": { "label": "page_type", "key": "page_type" }
    }
  ],
  "ok": false
}
```


## OpenAPI

````yaml POST /api/storefront/v1/headless/init
openapi: 3.0.1
info:
  title: Glood.AI API Reference
  description: Glood.AI API Reference
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://storefront.glood.ai
security:
  - bearerAuth: []
paths:
  /api/storefront/v1/headless/init:
    servers:
      - url: https://search.glood.ai
    post:
      description: >-
        Session bootstrap for the search suite. Call once per session (the
        `@glood/hydrogen` GloodProvider runs it automatically on mount) before
        instant/full search. Resolves the visitor, returns their history
        (browsed / cart / purchased product ids), a lean feature-flag config (no
        filter definitions, no filter tree, no templates), the Shopify
        storefront token and a fresh `visit_id`. Auth: `Authorization: Bearer
        <gl_sf_...>` + `x-shop`.
      parameters:
        - name: x-shop
          in: header
          description: >-
            Shopify store URL. Resolves the shop for the request (headless does
            not accept `?shop=`).
          required: true
          schema:
            type: string
            example: shop.myshopify.com
      requestBody:
        description: Session context. All fields optional.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HeadlessSearchInitRequest'
      responses:
        '200':
          description: Visitor context, history, lean config and token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HeadlessSearchInitResponse'
        '400':
          description: Validation or shop error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    HeadlessSearchInitRequest:
      type: object
      description: >-
        Search session bootstrap input (from `initSchema`). Every field is
        optional; send the identity triple you have so the visitor profile and
        history resolve correctly.
      properties:
        page_type:
          type: string
          description: >-
            Type of the page the session starts on. Used only for
            context/attribution.
          enum:
            - product_page
            - collection
            - home
            - cart
            - order_confirm
            - blog
            - ajax_cart
            - '404'
            - checkout
            - returns
            - search
            - other
        page_url:
          type: string
          description: Full URL of the page the session starts on.
        session_id:
          type: string
          description: >-
            Browsing-session id (defaulted from the SDK session cookie). Ties
            the visit to a session for analytics.
        locale:
          type: string
          description: BCP-47 locale for locale-aware indexes and the echoed metadata.
          default: en-US
          example: en-US
        market:
          type: integer
          description: Shopify market id for market-aware pricing / catalog.
        publication_ids:
          type: array
          items:
            oneOf:
              - type: string
                pattern: ^[0-9]+$
              - type: integer
          maxItems: 50
          description: >-
            Optional. Numeric Shopify publication (sales channel) ids. When
            present, only products published on at least one of these channels
            are returned and the default "published to the Online Store" gate is
            replaced by this filter; market and B2B filters still apply. A
            single id may be sent without the array wrapper. Each id must be one
            the merchant enabled under Settings → Sales channels; unknown ids
            return 400. The id is the numeric tail of
            gid://shopify/Publication/<id>.
          example:
            - '30085840999'
        visitor_id:
          type: string
          description: >-
            Anonymous device/browser UID (the `gl_s_uid` cookie). The primary
            personalization key; stays stable when a customer logs in.
        client_id:
          type: string
          description: Per-session / per-device identifier.
        customer_id:
          type: string
          description: >-
            Shopify customer id. Present only when the shopper is logged in;
            enables customer-level personalization.
    HeadlessSearchInitResponse:
      type: object
      description: >-
        Session bootstrap payload (from `getHeadlessInitResponse`): identity,
        visitor history, lean feature config, storefront token and a fresh visit
        id. Unlike the config endpoint it carries NO filter definitions and NO
        filter tree.
      properties:
        visit_id:
          type: string
          description: >-
            Fresh UUID identifying this search session. Echo it as `session_id`
            when sending events for this session.
          example: 3c90c3cc-0d44-4b50-8888-8dd25736052a
        visitor_id:
          type: string
          nullable: true
          description: >-
            Anonymous visitor id echoed from the request (null if none was
            sent). Persist it on the client.
        client_id:
          type: string
          nullable: true
          description: Client/device identifier echoed from the request, or null.
        customer_id:
          type: string
          nullable: true
          description: >-
            Shopify customer id echoed from the request when the shopper is
            authenticated, or null.
        visitor:
          type: object
          description: The visitor's recent activity, used to seed personalization.
          properties:
            browsed_products:
              type: array
              description: Product ids the visitor recently viewed.
              items:
                type: integer
            cart_products:
              type: array
              description: Product ids currently in the visitor's cart.
              items:
                type: integer
            purchased_products:
              type: array
              description: Product ids the visitor previously purchased.
              items:
                type: integer
        config:
          description: >-
            Lean feature-flag config (same shape as the config endpoint's
            `config`, produced by the same `getHeadlessConfigResponse`). No
            filter definitions, no filter tree, no templates.
          allOf:
            - $ref: '#/components/schemas/HeadlessFeatureConfig'
        token:
          type: string
          nullable: true
          description: >-
            Shopify storefront access token for direct Storefront API calls, or
            null.
        metadata:
          type: object
          description: Response metadata.
          properties:
            region:
              type: string
              description: Data-plane region serving this shop.
              example: toronto
            locale:
              type: string
              description: Resolved locale echoed from the request.
            market:
              type: integer
              nullable: true
              description: Echoed market id, or null.
    Error:
      required:
        - error
        - message
      type: object
      properties:
        error:
          type: integer
          format: int32
        message:
          type: string
    HeadlessFeatureConfig:
      type: object
      description: >-
        Merged instant / search / image feature config (from
        `getHeadlessConfigResponse`). Feature flags and functional settings only
        — no Liquid templates, no widget css/js.
      properties:
        instant_search_enabled:
          type: boolean
          description: Whether the instant (type-ahead) search feature is enabled.
        search_result_page_enabled:
          type: boolean
          description: Whether the full search results page feature is enabled.
        image_search_enabled:
          type: boolean
          description: Whether visual (image) search is enabled.
        personalization_enabled:
          type: boolean
          description: Whether personalization is enabled for this shop.
        personalization_config:
          type: object
          nullable: true
          description: Personalization tuning config, or null when disabled.
        auto_spell_correct_enabled:
          type: boolean
          description: Whether automatic spell correction is applied to instant search.
        instant_search_objects:
          type: array
          description: Default result blocks for instant search.
          items:
            type: string
          example:
            - product
            - collection
            - page
            - auto_suggestion
        exclude_out_of_stock:
          type: boolean
          description: Whether out-of-stock products are excluded from results.
        move_out_of_stock_at_end:
          type: boolean
          description: >-
            Whether out-of-stock products are pushed to the end instead of
            excluded.
        site_wide_search:
          type: object
          description: Site-wide search feature settings.
        search_result_count:
          type: integer
          description: Default number of instant-search results per type.
        default_ordering:
          type: string
          description: >-
            Sort applied when a search request omits `sort`, already resolved
            for the `target_page`/`target_id` in this request: the collection's
            configured sort when the merchant set one, otherwise the shop-wide
            default. Can be `collection_default` on a collection page, so
            surface it as the pre-selected option in your sort control rather
            than assuming `relevance`.
          example: relevance
        minimum_type_ahead_input_count:
          type: integer
          description: >-
            Minimum query length before instant search fires (below this,
            trending is returned).
        default_search_result_page_size:
          type: integer
          description: Default page size for the search results page.
        search_page_autocomplete_enabled:
          type: boolean
          description: Whether autocomplete is enabled on the search page.
        search_page_handle:
          type: string
          nullable: true
          description: Storefront handle of the search page.
        image_search_pages:
          type: object
          nullable: true
          description: Pages where image search is surfaced, or null.
        settings:
          type: object
          description: Functional feature settings only. Contains NO presentation css/js.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.