Skip to content
Get API key

Build a Bhagavad Gita Verse-of-the-Day Feature with the Bhagavad Gita API

4 min read

Fetch Bhagavad Gita chapters and verses as JSON with the Bhagavad Gita API, paginate with offset, and ship a verse-of-the-day card in your app.

A daily Gita verse is one of the most loved features in devotional and wellness apps. It gives users a reason to open the app every morning, and it is simple to build once you have the text in a clean, structured form. Mantrilo's Books API gives you exactly that.

In this tutorial you will use the Bhagavad Gita API from Mantrilo to list the Gita's chapters, page through verses, and build a verse of the day that is the same for every user on a given date and walks through all 700 verses over time.

Try it in one request

bash
curl https://api.mantrilo.com/v1/books/bhagavadGita/chapters/2 \
  -H "Authorization: Bearer $MANTRILO_API_KEY"

That returns Chapter 2's metadata and up to 30 of its verses as JSON.

Need a key? Get a free sandbox key. The sandbox previews the first three verses of the opening chapter of each sample title, which is enough to build and test everything below. Full text is available on paid plans.

What you'll build

  1. A list of the Gita's 18 chapters with their verse counts
  2. A function that fetches any verse by chapter and number
  3. A deterministic verse of the day that is the same for every user on a given date
  4. A card that displays it

Step 1: Find the Gita in the catalog

The book catalog lists every title available to your key:

bash
curl https://api.mantrilo.com/v1/books \
  -H "Authorization: Bearer $MANTRILO_API_KEY"

The catalog uses cursor pagination and returns up to 24 titles per page. If there are more, pass the response's nextCursor back as cursor to get the next page. Note the Gita's id; it's bhagavadGita.

Step 2: Read the chapter index

GET /v1/books/{id} returns the book's metadata and its chapter index:

javascript
const API = "https://api.mantrilo.com/v1";
const headers = { Authorization: `Bearer ${process.env.MANTRILO_API_KEY}` };

async function getJson(path) {
  const res = await fetch(`${API}${path}`, { headers });
  const json = await res.json();
  if (!res.ok) throw new Error(json.error?.message || `HTTP ${res.status}`);
  return json.data;
}

export async function getGitaChapters() {
  const book = await getJson("/books/bhagavadGita");
  return book.chapters; // [{ number: 1, verseCount: 47, ... }, ...]
}

The Gita has 18 chapters and 700 verses. Chapter 18 is the longest at 78 verses and Chapter 2 has 72, so a single chapter can span several pages of results.

Step 3: Fetch any verse, with pagination

A chapter request returns up to 30 verses at a time. To reach later verses, pass offset. The response tells you where the next page starts in data.nextOffset.

javascript
const PAGE = 30;

export async function getVerse(chapter, verse) {
  const offset = Math.floor((verse - 1) / PAGE) * PAGE;
  const page = await getJson(`/books/bhagavadGita/chapters/${chapter}?offset=${offset}`);
  return page.verses[(verse - 1) - offset];
}

To load a whole chapter, for a reading screen, loop until there is no nextOffset:

javascript
export async function getChapter(chapter) {
  const verses = [];
  let offset = 0;
  while (offset !== undefined && offset !== null) {
    const page = await getJson(`/books/bhagavadGita/chapters/${chapter}?offset=${offset}`);
    verses.push(...page.verses);
    offset = page.nextOffset;
  }
  return verses;
}

Step 4: Pick the verse of the day

A good verse of the day has two properties. Everyone who opens the app on the same date sees the same verse, so people can talk about it. And over time it covers every verse, not the same famous dozen.

The simplest way to get both is to count days since a fixed date and walk through the Gita in order:

javascript
export function verseForDate(dateISO, chapters) {
  const total = chapters.reduce((sum, ch) => sum + ch.verseCount, 0); // 700
  const day = Math.floor(Date.parse(`${dateISO}T00:00:00Z`) / 86_400_000);
  let n = day % total;

  for (const ch of chapters) {
    if (n < ch.verseCount) return { chapter: ch.number, verse: n + 1 };
    n -= ch.verseCount;
  }
}

This reads the entire Gita in 700 days, one verse a day, then starts again. If you'd rather jump around, shuffle the list of 700 positions once with a fixed seed and index into it the same way.

Compute dateISO in the user's time zone, so a user in California doesn't see tomorrow's verse at 5 p.m.:

javascript
const dateISO = new Intl.DateTimeFormat("en-CA", { timeZone: userTimeZone }).format(new Date());

Step 5: Serve it from your API

Put it together behind one endpoint, and cache the result. The verse for a given date never changes.

javascript
import express from "express";
const app = express();
const cache = new Map();

app.get("/api/gita/today", async (req, res) => {
  try {
    const tz = String(req.query.tz || "UTC");
    const dateISO = new Intl.DateTimeFormat("en-CA", { timeZone: tz }).format(new Date());
    if (!cache.has(dateISO)) {
      const chapters = await getGitaChapters();
      const { chapter, verse } = verseForDate(dateISO, chapters);
      cache.set(dateISO, { chapter, verse, text: await getVerse(chapter, verse) });
    }
    res.json(cache.get(dateISO));
  } catch (err) {
    res.status(502).json({ error: err.message });
  }
});

Your app then calls /api/gita/today?tz=America/New_York and renders the verse: the Devanagari and its transliteration, and a reference like "Bhagavad Gita 2.47".

Ideas to extend it

  • Push notifications. Send the day's verse at the user's chosen time.
  • Share cards. Render the verse as an image for WhatsApp and Instagram.
  • Chapter reader. Use getChapter() to build a full reading screen with bookmarks keyed by chapter.verse.
  • More texts. The same endpoints serve every book in the catalog, such as the Upanishads.

Why use Mantrilo for Gita content

You can find Gita text in many places. What is harder to find is text that is structured, paginated and consistent, with Devanagari and transliteration in separate fields and stable chapter and verse numbers for bookmarks and sharing.

Mantrilo gives you that for the Gita and for the rest of its catalog, such as the Upanishads, through the same endpoints. When your verse of the day grows into a reader, a mantra player or a Panchang, it is still one integration.

FAQ

Is there a Bhagavad Gita API that returns JSON? Yes. Mantrilo's Books API returns the Gita's chapters and verses as JSON, with pagination for long chapters.

How many verses does each request return? Up to 30 verses per chapter request. Use offset and data.nextOffset for the rest.

Can I try the Gita API for free? Yes. The sandbox previews the first three verses of the opening chapter so you can build your integration before choosing a plan.

Does it include Sanskrit and transliteration? Yes. Each verse returns the Sanskrit text in Devanagari (sanskrit) and a Roman transliteration with diacritics (transliteration) in separate fields.

Start today. Get a free sandbox key, preview the Bhagavad Gita and explore the Books API.