Skip to main content

Client API

The client API provides the core functionality for creating and configuring your Glood SDK instance.

createGlood()

Creates a new Glood client instance with the specified configuration.

Signature

Parameters

Basic Usage

Advanced Usage

The version option selects the headless API version. Version 3 (default) is the full suite — init, sections, events, and the recommendations variants. Version 2 is legacy and only supports recommendations, authenticating by shop header alone (no bearer token).

Error Handling

The function throws errors for invalid configurations:

GloodConfig Interface

Configuration object for creating a Glood client.

Properties

App Configuration

The apps property allows per-app customization:
The recommendations app config has this structure:

Default App Configuration

When apps is not provided, these defaults are used:

GloodClient Interface

The client instance returned by createGlood().

Properties

Methods

use()

Registers an app module with the client.
Parameters:
  • appModuleOrFactory: App module function or factory
Returns: The client instance (for method chaining) Usage:

getEnabledApps()

Returns all registered app instances.
Returns: Array of enabled app instances Usage:

getApp()

Gets a specific app by name.
Parameters:
  • name: App name (‘recommendations’)
Returns: App instance or undefined if not found Usage:

getInitData()

Reads the /v3/headless/init response saved after the page-load session init. This is the synchronous, non-React counterpart to the useGloodInit() hook.
Returns: The InitResponse once init has resolved, or null if init hasn’t run yet or the client is configured for version: 2 (init is v3-only). Usage:
Read-only for app code. The value is written only by the SDK’s page-load init flow (runHeadlessInit, run automatically by GloodProvider for v3 clients).

Configuration Examples

Basic Setup

Minimal configuration with defaults:

Environment-Specific Setup

Different configurations for different environments:

Legacy v2 Setup

Pin the client to the legacy v2 recommendations API:

Error Handling

The client provides comprehensive error handling:

Validation Errors

Runtime Errors

Domain Validation

Best Practices

1. Environment Variables

Always use environment variables for sensitive data:

2. Debug Mode

Enable debug mode in development:

3. Error Handling

Wrap client creation in try-catch for production:

4. Method Chaining

Use method chaining for cleaner code:

See Also