Skip to Content
lio-client is in active development. APIs may change.
Getting Started

Getting Started

Get up and running with lio-client in minutes.

Installation

npm install @lytics/lio-client

Requirements: Node.js ≥ 18 or modern browser with ES2020 support

Basic Setup

Create and initialize your Lytics client:

import { createLioClient } from '@lytics/lio-client'; const lio = createLioClient({ apiKey: 'YOUR_LYTICS_API_KEY', baseUrl: 'https://api.lytics.io' // Optional, defaults to api.lytics.io }); await lio.init();

Never expose API keys in client-side code. Use environment variables and server-side execution.

Environment Variables

Store your API key securely:

.env.local
LYTICS_API_KEY=your_api_key_here

Then use it in your code:

const lio = createLioClient({ apiKey: process.env.LYTICS_API_KEY });

First API Call

Test your setup by listing workflows:

import { createLioClient } from '@lytics/lio-client'; const lio = createLioClient({ apiKey: process.env.LYTICS_API_KEY }); await lio.init(); // List all workflows const workflows = await lio.workflows.list(); console.log('Workflows:', workflows); // Get content by URL const content = await lio.content.getByUrl('example.com/blog/post'); console.log('Content:', content); // Get schema const schema = await lio.schema.get('content'); console.log('Schema:', schema);

With Contentstack Plugin

Add Contentstack-specific features:

npm install @lytics/lio-client @lytics/lio-client-contentstack
import { createLioClient } from '@lytics/lio-client'; import { contentstackPlugin } from '@lytics/lio-client-contentstack'; const lio = createLioClient({ apiKey: process.env.LYTICS_API_KEY, plugins: [contentstackPlugin()] }); await lio.init(); // Contentstack-specific methods const status = await lio.contentstack.getSyncStatus(); const enriched = await lio.contentstack.enrich(cmsEntry);

TypeScript

lio-client is TypeScript-first. Types are included automatically:

import { createLioClient, type LioClient, type WorkflowListResponse } from '@lytics/lio-client'; const lio: LioClient = createLioClient({ apiKey: process.env.LYTICS_API_KEY }); const workflows: WorkflowListResponse = await lio.workflows.list();

Error Handling

All API calls may throw errors. Use try/catch:

try { const content = await lio.content.getByUrl('example.com/page'); console.log('Content found:', content); } catch (error) { if (error.status === 404) { console.log('Content not found'); } else { console.error('API error:', error.message); } }

Lifecycle

The client supports proper initialization and cleanup:

// Initialize (required) await lio.init(); // Check if ready if (lio.isReady()) { // Make API calls } // Cleanup when done await lio.destroy();

Next Steps

  • Core API - Learn about Workflows, Content, and Schema APIs
  • Plugins - Extend with Contentstack or build your own
  • Examples - Real-world integration patterns
Last updated on