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
Theapps property allows per-app customization:
Default App Configuration
Whenapps is not provided, these defaults are used:
GloodClient Interface
The client instance returned bycreateGlood().
Properties
Methods
use()
Registers an app module with the client.appModuleOrFactory: App module function or factory
getEnabledApps()
Returns all registered app instances.getApp()
Gets a specific app by name.name: App name (‘recommendations’)
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.
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
- React Components - GloodProvider and hooks
- App Modules - recommendations()
- Configuration Guide - Detailed configuration options
- Types Reference - TypeScript interface definitions