Skip to main content

BibleClient

The BibleClient class provides methods for fetching Bible data from the YouVersion Platform API. It supports retrieving Bible versions, books, chapters, verses, passages, and the Verse of the Day (VOTD).

Constructor

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

const apiClient = new ApiClient({ appKey: 'your-app-key' });
const bibleClient = new BibleClient(apiClient);
client
ApiClient
required
An instance of ApiClient used to make HTTP requests.

Methods

getVersions()

Fetches a collection of Bible versions filtered by language ranges.
async getVersions(
  language_ranges: string | string[],
  license_id?: string | number,
  options?: GetVersionsOptions
): Promise<Collection<BibleVersion>>
language_ranges
string | string[]
required
One or more language codes or ranges to filter versions (e.g., "en", "en*", ["en", "es"]).Supports wildcards: "en*" matches all English variants.
license_id
string | number
Optional license ID to filter versions by specific licensing.
options
GetVersionsOptions
Optional pagination and field selection options.
Returns
Promise<Collection<BibleVersion>>
A collection of Bible versions matching the language criteria.

Examples

// Get all English Bible versions
const versions = await bibleClient.getVersions('en*');

console.log(`Found ${versions.data.length} versions`);
versions.data.forEach(version => {
  console.log(`${version.abbreviation}: ${version.title}`);
});

getVersion()

Fetches a specific Bible version by its ID.
async getVersion(id: number): Promise<BibleVersion>
id
number
required
The version ID (must be a positive integer).
Returns
Promise<BibleVersion>
The requested Bible version object.

Example

// Get the NIV (version ID 111)
const niv = await bibleClient.getVersion(111);

console.log(niv.title); // "New International Version"
console.log(niv.abbreviation); // "NIV"
console.log(niv.language_tag); // "en"
console.log(niv.books); // ["GEN", "EXO", "LEV", ...]

getBooks()

Fetches all books for a given Bible version.
async getBooks(
  versionId: number,
  canon?: CANON
): Promise<Collection<BibleBook>>
versionId
number
required
The Bible version ID.
canon
CANON
Optional canon filter: "old_testament", "new_testament", or "deuterocanon".
Returns
Promise<Collection<BibleBook>>
Collection of Bible books. Each book may include an optional intro field with metadata for book introductions.

Examples

// Get all books in a version
const books = await bibleClient.getBooks(111);

books.data.forEach(book => {
  console.log(`${book.id}: ${book.title} (${book.canon})`);
});

getBook()

Fetches a specific book by USFM code for a given version.
async getBook(versionId: number, book: string): Promise<BibleBook>
versionId
number
required
The Bible version ID.
book
string
required
The 3-character book identifier code (e.g., “GEN”, “MAT”, “REV”).
Returns
Promise<BibleBook>
The requested Bible book, which may include an optional intro field. Use the passage_id from the intro with getPassage() to fetch introduction content.

Example

// Get the book of John
const john = await bibleClient.getBook(111, 'JHN');

console.log(john.title); // "John"
console.log(john.full_title); // "The Gospel According to John"
console.log(john.canon); // "new_testament"

// Check for introduction
if (john.intro) {
  const intro = await bibleClient.getPassage(111, john.intro.passage_id);
  console.log(intro.content);
}

getChapters()

Fetches all chapters for a specific book in a version.
async getChapters(
  versionId: number,
  book: string
): Promise<Collection<BibleChapter>>
versionId
number
required
The Bible version ID.
book
string
required
The 3-character book identifier (e.g., “GEN”, “MAT”).
Returns
Promise<Collection<BibleChapter>>
Collection of chapters in the book.

Example

// Get all chapters in Matthew
const chapters = await bibleClient.getChapters(111, 'MAT');

console.log(`Matthew has ${chapters.data.length} chapters`);

chapters.data.forEach(chapter => {
  console.log(`Chapter ${chapter.title}: ${chapter.passage_id}`);
});

getChapter()

Fetches a specific chapter for a book in a version.
async getChapter(
  versionId: number,
  book: string,
  chapter: number
): Promise<BibleChapter>
versionId
number
required
The Bible version ID.
book
string
required
The 3-character book identifier (e.g., “GEN”, “MAT”).
chapter
number
required
The chapter number (must be a positive integer).
Returns
Promise<BibleChapter>
The requested Bible chapter.

Example

// Get John chapter 3
const chapter = await bibleClient.getChapter(111, 'JHN', 3);

console.log(chapter.title); // "3"
console.log(chapter.passage_id); // "JHN.3"

getVerses()

Fetches all verses for a specific chapter in a book and version.
async getVerses(
  versionId: number,
  book: string,
  chapter: number
): Promise<Collection<BibleVerse>>
versionId
number
required
The Bible version ID.
book
string
required
The 3-character book identifier (e.g., “GEN”, “MAT”).
chapter
number
required
The chapter number.
Returns
Promise<Collection<BibleVerse>>
Collection of verses in the chapter.

Example

// Get all verses in John 3
const verses = await bibleClient.getVerses(111, 'JHN', 3);

console.log(`John 3 has ${verses.data.length} verses`);

// Fetch content for each verse
for (const verse of verses.data) {
  const passage = await bibleClient.getPassage(111, verse.passage_id);
  console.log(`${verse.title}: ${passage.content}`);
}

getVerse()

Fetches a specific verse from a chapter, book, and version.
async getVerse(
  versionId: number,
  book: string,
  chapter: number,
  verse: number
): Promise<BibleVerse>
versionId
number
required
The Bible version ID.
book
string
required
The 3-character book identifier (e.g., “GEN”, “MAT”).
chapter
number
required
The chapter number.
verse
number
required
The verse number.
Returns
Promise<BibleVerse>
The requested Bible verse.

Example

// Get John 3:16
const verse = await bibleClient.getVerse(111, 'JHN', 3, 16);

console.log(verse.passage_id); // "JHN.3.16"
console.log(verse.title); // "16"

// Fetch the actual verse content
const passage = await bibleClient.getPassage(111, verse.passage_id);
console.log(passage.content);

getPassage()

Fetches a passage (range of verses) from the Bible using the passages endpoint. Returns HTML or text formatted content.
async getPassage(
  versionId: number,
  usfm: string,
  format?: 'html' | 'text',
  include_headings?: boolean,
  include_notes?: boolean
): Promise<BiblePassage>
versionId
number
required
The Bible version ID.
usfm
string
required
The USFM reference. Supports:
  • Single verse: "JHN.3.16"
  • Verse range: "JHN.3.1-5"
  • Entire chapter: "GEN.1"
  • Multiple chapters: "GEN.1-2"
format
'html' | 'text'
default:"html"
The format to return. Use "html" for formatted content or "text" for plain text.
include_headings
boolean
Whether to include section headings in the content.
include_notes
boolean
Whether to include footnotes and study notes in the content.
Returns
Promise<BiblePassage>
The requested passage with formatted content.

Examples

// Get John 3:16
const verse = await bibleClient.getPassage(111, 'JHN.3.16');

console.log(verse.reference); // "John 3:16"
console.log(verse.content); // HTML content

getIndex()

Fetches the complete indexing structure for a Bible version, containing the full hierarchy of books, chapters, and verses.
async getIndex(versionId: number): Promise<BibleIndex>
versionId
number
required
The Bible version ID.
Returns
Promise<BibleIndex>
The complete Bible index structure.

Example

// Get the complete index for NIV
const index = await bibleClient.getIndex(111);

console.log(`Text direction: ${index.text_direction}`);
console.log(`Total books: ${index.books.length}`);

// Navigate the structure
index.books.forEach(book => {
  console.log(`\n${book.title} (${book.id})`);
  console.log(`  Chapters: ${book.chapters.length}`);
  
  book.chapters.forEach(chapter => {
    console.log(`  Chapter ${chapter.title}: ${chapter.verses.length} verses`);
  });
});

// Find a specific verse
const genesis = index.books.find(b => b.id === 'GEN');
const chapter1 = genesis?.chapters.find(c => c.title === '1');
const verse1 = chapter1?.verses.find(v => v.title === '1');
console.log(verse1?.id); // Verse ID

getAllVOTDs()

Fetches the verse of the day calendar for an entire year (all 366 days).
async getAllVOTDs(): Promise<Collection<VOTD>>
Returns
Promise<Collection<VOTD>>
Collection of VOTD objects for all days of the year.

Example

// Get all verse of the day entries
const votds = await bibleClient.getAllVOTDs();

console.log(`Total VOTD entries: ${votds.data.length}`);

// Get today's VOTD
const today = new Date();
const dayOfYear = Math.floor(
  (today - new Date(today.getFullYear(), 0, 0)) / 86400000
);

const todayVOTD = votds.data.find(v => v.day === dayOfYear);
if (todayVOTD) {
  const passage = await bibleClient.getPassage(111, todayVOTD.passage_id);
  console.log(`Today's verse: ${passage.reference}`);
  console.log(passage.content);
}

getVOTD()

Fetches the passage ID for a specific day of the year’s Verse of the Day.
async getVOTD(day: number): Promise<VOTD>
day
number
required
The day of the year (1-366).
Returns
Promise<VOTD>
The VOTD for the specified day with the passage ID.

Examples

// Get VOTD for day 1 (January 1)
const votd = await bibleClient.getVOTD(1);

console.log(`Day ${votd.day}: ${votd.passage_id}`);

// Fetch the actual verse content
const passage = await bibleClient.getPassage(111, votd.passage_id);
console.log(passage.reference);
console.log(passage.content);

Complete Example

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

// Initialize clients
const apiClient = new ApiClient({
  appKey: process.env.YOUVERSION_APP_KEY!,
});
const bibleClient = new BibleClient(apiClient);

// Find English versions
const versions = await bibleClient.getVersions('en*');
const niv = versions.data.find(v => v.abbreviation === 'NIV');

if (niv) {
  console.log(`Using ${niv.title}`);
  
  // Get the books
  const books = await bibleClient.getBooks(niv.id);
  console.log(`${books.data.length} books available`);
  
  // Get New Testament only
  const ntBooks = await bibleClient.getBooks(niv.id, 'new_testament');
  console.log(`${ntBooks.data.length} NT books`);
  
  // Get John 3:16
  const verse = await bibleClient.getPassage(niv.id, 'JHN.3.16');
  console.log(`\n${verse.reference}`);
  console.log(verse.content);
  
  // Get today's verse of the day
  const today = new Date();
  const dayOfYear = Math.floor(
    (today - new Date(today.getFullYear(), 0, 0)) / 86400000
  );
  const votd = await bibleClient.getVOTD(dayOfYear);
  const votdPassage = await bibleClient.getPassage(niv.id, votd.passage_id);
  
  console.log(`\nVerse of the Day: ${votdPassage.reference}`);
  console.log(votdPassage.content);
}

Best Practices

When searching for versions, use wildcards to match all language variants:
// Match all English variants (en, en-US, en-GB, etc.)
const versions = await bibleClient.getVersions('en*');

// Match specific language
const spanishVersions = await bibleClient.getVersions('es');
For better performance, use getPassage() to fetch multiple verses at once:
// ❌ Not recommended - multiple API calls
for (let i = 1; i <= 5; i++) {
  const verse = await bibleClient.getVerse(111, 'JHN', 3, i);
  // ...
}

// ✅ Recommended - single API call
const passage = await bibleClient.getPassage(111, 'JHN.3.1-5');
Version and book metadata rarely changes, so cache it to reduce API calls:
// Cache versions
const versionsCache = new Map<string, Collection<BibleVersion>>();

async function getVersionsCached(lang: string) {
  if (!versionsCache.has(lang)) {
    const versions = await bibleClient.getVersions(lang);
    versionsCache.set(lang, versions);
  }
  return versionsCache.get(lang)!;
}
When fetching all results, handle pagination properly:
async function getAllVersions(language: string) {
  const allVersions: BibleVersion[] = [];
  let nextToken: string | null = null;
  
  do {
    const result = await bibleClient.getVersions(language, undefined, {
      page_size: 50,
      page_token: nextToken || undefined
    });
    
    allVersions.push(...result.data);
    nextToken = result.next_page_token;
  } while (nextToken);
  
  return allVersions;
}
When accepting user input for passages, validate the format:
function isValidUSFM(usfm: string): boolean {
  // Basic validation for USFM format
  return /^[A-Z]{3}\.\d+(\.\d+)?(-\d+)?$/.test(usfm);
}

const userInput = 'JHN.3.16';
if (isValidUSFM(userInput)) {
  const passage = await bibleClient.getPassage(111, userInput);
} else {
  console.error('Invalid USFM format');
}

Build docs developers (and LLMs) love