Chapters API
Purpose: Read chapter lists and chapter details.
Use this when: You have a backend and need chapter metadata.
Do not use this when: You only have frontend or mobile code with no backend.
Backend required: Yes.
Allowed runtimes: Node.js, serverless functions, workers.
Required credentials: client_id, client_secret, Content API access.
Minimal import: @quranjs/api/server.
Use @quranjs/api/server.
import { createServerClient } from "@quranjs/api/server";
const client = createServerClient({
clientId: process.env.QF_CLIENT_ID!,
clientSecret: process.env.QF_CLIENT_SECRET!,
});
const chapters = await client.content.v4.chapters.list();
const chapter = await client.content.v4.chapters.get("1");
const info = await client.content.v4.chapters.getInfo("1");
const infoResponse = await client.content.v4.chapters.getInfoResponse("1", {
includeResources: true,
resourceId: 58,
});
Chapter Info Resources
Use getInfo when you only need the resolved chapter info body. Use getInfoResponse when you also need to inspect the optional resources list returned by includeResources: true, or when you need to handle chapterInfo: null for a resource that has no content for the selected chapter.
const { chapterInfo, resources } =
await client.content.v4.chapters.getInfoResponse("1", {
includeResources: true,
});
const ibnAshur = resources?.find(
(resource) => resource.slug === "en-tafsir-ibn-ashur",
);
const selected = await client.content.v4.chapters.getInfoResponse("1", {
resourceId: ibnAshur?.slug,
});
if (selected.chapterInfo) {
console.log(selected.chapterInfo.resourceId, selected.chapterInfo.text);
}
Common Mistake
Do not call Chapters from @quranjs/api/public. Content APIs are server-side for confidential clients. Production defaults are already built in.