Skip to content
Get API key

Guides · Books

Load the Upanishads into your app

Call one collection directly, page through it, then open a book, chapter or verse.

Try this request in the sandbox

1 Make a working request

GET /v1/books?collection=upanishads&limit=3
curl "$MANTRILO_API_URL/v1/books?collection=upanishads&limit=3" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
Sandbox collection response200 OK
{
  "data": [
    {
      "id": "ishaUpanishad",
      "title": "Īśāvāsya Upaniṣad",
      "author": "Vedic Rishis",
      "category": null,
      "subcategory": null,
      "collection": {
        "id": "upanishads",
        "name": "Upanishads"
      },
      "description": "One of the shortest and most profound Upanishads, revealing the nature of the Supreme Lord who pervades all.",
      "verseCount": 18
    }
  ],
  "nextCursor": null,
  "sandbox": true,
  "requestId": "request-id"
}
  • Book and chapter indexGET /v1/books/ishaUpanishad
  • First chapterGET /v1/books/ishaUpanishad/chapters/1

2 Call it from your server

Keep the key in your backend and return only the content to your app. This Node.js server exposes one route your app can call.

server.mjs
// server.mjs · Node.js 22+
import { createServer } from 'node:http';

const apiKey = process.env.MANTRILO_API_KEY;
if (!apiKey) throw new Error('Set MANTRILO_API_KEY on your server.');
const base = process.env.MANTRILO_API_URL ?? "https://api.mantrilo.com";

async function mantrilo(path, input) {
  const response = await fetch(base + path, {
    method: input ? 'POST' : 'GET',
    headers: {
      Authorization: 'Bearer ' + apiKey,
      ...(input ? { 'Content-Type': 'application/json' } : {}),
    },
    ...(input ? { body: JSON.stringify(input) } : {}),
    signal: AbortSignal.timeout(20000),
    redirect: 'error',
  });
  const result = await response.json();
  if (!response.ok) throw Object.assign(new Error('Mantrilo request failed'), {
    status: response.status, requestId: result.requestId,
  });
  return result;
}

async function load(incoming) {
  const params = new URLSearchParams({ collection: 'upanishads', limit: '3' });
  const cursor = incoming.searchParams.get('cursor');
  if (cursor) params.set('cursor', cursor);
  return mantrilo('/v1/books?' + params);
}

createServer(async (req, res) => {
  const incoming = new URL(req.url, 'http://localhost');
  res.setHeader('Content-Type', 'application/json');
  if (req.method !== 'GET' || incoming.pathname !== '/api/mantrilo-guide') {
    res.writeHead(404).end(JSON.stringify({ error: 'Not found' }));
    return;
  }
  try {
    const result = await load(incoming);
    res.end(JSON.stringify(result));
  } catch (error) {
    res.writeHead(error.status ?? 502).end(JSON.stringify({
      error: 'Could not load this content',
      requestId: error.requestId,
    }));
  }
}).listen(3000, '127.0.0.1');
In your view
const books = data.map(book => ({ id: book.id, title: book.title, description: book.description }));

3 Inputs and pagination

collection is a collection id: upanishads, bhagavad-gita, advaita-vedanta-prakarana-granthas, vedanta or yoga. limit is 1–100 (default 24). Pass nextCursor as cursor for the next page; it is null on the last page. Every book in the response carries collection.id, so the same id works for links back to the collection. Sandbox keys return Isha Upanishad for this collection, with nextCursor set to null. Paid keys can page through the available collection. Collections without a designated sample return an empty sandbox page.

List data[].title and description, then open a book with GET /v1/books/{id}. Its chapters[] gives the chapter numbers for GET /v1/books/{id}/chapters/{chapter}, whose verses[] carry each verse number.

4 Quota

Each collection page, book index and chapter page uses one request. Paging three books at a time through a collection of twelve uses four requests.

Requests read the base URL from MANTRILO_API_URL. The server example falls back to https://api.mantrilo.com.