Skip to main content

Core Package Overview

The @youversion/platform-core package provides type-safe TypeScript API clients for accessing YouVersion Platform services. It’s framework-agnostic with zero React dependencies, making it suitable for server-side, Node.js, or any JavaScript environment.

Installation

pnpm add @youversion/platform-core
Get your App Key at platform.youversion.com

Core Clients

The package provides several specialized clients for different API services:

ApiClient

HTTP client for making authenticated API requests

BibleClient

Access Bible versions, books, chapters, verses, and passages

LanguagesClient

Get supported languages and their metadata

HighlightsClient

Manage user Bible highlights (requires OAuth)

Quick Start

import { ApiClient, BibleClient } from '@youversion/platform-core';

// Initialize the API client
const apiClient = new ApiClient({
  appKey: 'YOUR_APP_KEY',
  apiHost: 'api.youversion.com', // optional
  timeout: 10000, // optional, defaults to 10000ms
});

// Create specialized clients
const bibleClient = new BibleClient(apiClient);

// Fetch Bible versions in English
const versions = await bibleClient.getVersions('en*');
console.log(versions.data[0].title);

// Get John 3:16
const passage = await bibleClient.getPassage(
  versions.data[0].id,
  'JHN.3.16'
);
console.log(passage.content);

Architecture

Schema-First Design

All data types are defined using Zod schemas in the schemas/ directory. This provides:
  • Runtime validation of API responses
  • Type safety with automatic TypeScript types
  • Single source of truth for data structures

Client Hierarchy

ApiClient (HTTP layer)
   ├── BibleClient (Bible data operations)
   ├── LanguagesClient (Language data)
   └── HighlightsClient (User highlights)
All specialized clients receive an ApiClient instance in their constructor, allowing them to make authenticated HTTP requests.

Configuration

appKey
string
required
Your YouVersion Platform App Key obtained from platform.youversion.com
apiHost
string
default:"api.youversion.com"
The API host to connect to. Only change this for testing purposes.
timeout
number
default:10000
Request timeout in milliseconds. Requests will abort after this duration.
installationId
string
default:"web-sdk-default"
Unique identifier for this installation. Used for analytics and tracking.

Type Safety

All API responses are validated against Zod schemas and return strongly-typed data:
import type { BibleVersion, BiblePassage, Collection } from '@youversion/platform-core';

// Collection type for paginated responses
const versions: Collection<BibleVersion> = await bibleClient.getVersions('en*');

// Iterate with full type safety
versions.data.forEach((version: BibleVersion) => {
  console.log(version.title, version.language_tag);
});

// BiblePassage type
const passage: BiblePassage = await bibleClient.getPassage(1, 'JHN.3.16');
console.log(passage.reference, passage.content);

Error Handling

API errors are thrown as standard JavaScript Error objects with additional properties:
try {
  const passage = await bibleClient.getPassage(9999, 'INVALID.1.1');
} catch (error) {
  if (error instanceof Error) {
    console.error(error.message);
    // Error objects include HTTP status if available
    const httpError = error as Error & { status?: number; statusText?: string };
    console.error(`Status: ${httpError.status} ${httpError.statusText}`);
  }
}

Utility Functions

getAdjacentChapter

Computes the next or previous chapter across book boundaries, with support for intro chapters.
import { getAdjacentChapter } from '@youversion/platform-core';

// Get next chapter
const next = getAdjacentChapter(
  books,           // Array of BibleBook with populated chapters
  'JHN',           // Current book USFM ID
  '3',             // Current chapter ID
  'next'           // Direction: 'next' | 'previous'
);

if (next) {
  console.log(`Next: ${next.bookId} ${next.chapterId}`);
  // Navigate to next.bookId and next.chapterId
}

// Get previous chapter
const prev = getAdjacentChapter(books, 'JHN', '3', 'previous');
books
BibleBook[]
required
Ordered array of Bible books with populated chapters
currentBookId
string
required
USFM book ID (e.g., “JHN”, “GEN”, “REV”)
currentChapterId
string
required
Chapter ID string (e.g., “1”, “2”, “INTRO”)
direction
'next' | 'previous'
required
Navigation direction
Returns: { bookId: string; chapterId: string } | null Returns the target book and chapter IDs, or null if at Bible boundaries (beginning or end). Features:
  • Handles intro chapters correctly (skips when navigating forward)
  • Crosses book boundaries automatically
  • Returns null at Bible boundaries instead of wrapping

Framework Agnostic

This package has zero React dependencies and can be used in:
  • ✅ Node.js servers
  • ✅ Next.js API routes
  • ✅ Express/Fastify backends
  • ✅ Browser applications
  • ✅ React Native apps
  • ✅ Any JavaScript environment
For React applications, consider using @youversion/platform-react-hooks which provides React hooks built on top of this package.

Authentication

Some endpoints (like highlights) require OAuth authentication. See the Authentication guide for implementing PKCE authentication flow.

React Hooks

React hooks wrapping these clients with state management

React UI

Pre-built UI components for React applications

Next Steps

BibleClient

Learn about Bible data methods

Authentication

Implement OAuth PKCE flow

API Reference

Browse the complete API reference

Build docs developers (and LLMs) love