โ† Recipes

Generate a kundli report: six calls, one document

There is no single "kundli PDF" endpoint, and that is deliberate: every product wants different sections in a different design. You fetch the sections in parallel, keep the engine version with them, and render the document yourself.

You build
A kundli document (JSON + HTML) assembled from six parallel calls
Code
Node.js - no SDK, runnable as shown

Updated

What the API does and does not return

Every calculation endpoint returns JSON. None returns a PDF or rendered HTML. The asynchronous report jobs under /v1/reports/* cover compatibility, batch matching and multi-year Varshphal, not a natal kundli. So a kundli report is a composition, and you choose its sections. A typical first version:

Sections and where they come from
SectionEndpointPlan
Lagna, Moon sign, nakshatra/v1/birth-detailsFree
Rashi chart (D1)/v1/charts/birthFree
Navamsa (D9)/v1/charts/varga with division: 9Hobby
Mahadasha table/v1/dasha/vimshottari with levels: 1Free
Yogas present/v1/yogas - 55 checked, filter presentHobby
Mangal dosha/v1/dosha/mangalFree

Each is one billable request, so this report costs six calls. On the Free plan the two Hobby sections answer 403 PLAN_REQUIRED - see plan required - which is a useful default: build the free sections first and add the rest when you upgrade.

Fetch in parallel, assemble once

The six calls are independent - all take the same five birth fields - so send them together. The program keeps only what the template needs and records engine_version alongside it, then writes HTML to stdout and a one-line summary to stderr:

kundli-report.mjs

Node.js
// kundli-report.mjs - node kundli-report.mjs > kundli.html
const API = process.env.ASTRONODE_API_URL ?? "https://api.astronode.dev";
const KEY = process.env.ASTRONODE_API_KEY;

const post = async (path, body) => {
  const res = await fetch(API + path, {
    method: "POST",
    headers: { authorization: `Bearer ${KEY}`, "content-type": "application/json" },
    body: JSON.stringify(body),
  });
  const json = await res.json();
  if (!res.ok) throw new Error(`${path}: ${json.error.code} ${json.error.message}`);
  return json;
};

const birth = { date: "1973-04-24", time: "17:25:00", tz_offset_minutes: 330, lat: 19.076, lng: 72.8777 };

// Six independent calls: run them together. Each is one billable request.
const [details, d1, d9, dasha, yogas, mangal] = await Promise.all([
  post("/v1/birth-details", birth),
  post("/v1/charts/birth", birth),
  post("/v1/charts/varga", { ...birth, division: 9 }),
  post("/v1/dasha/vimshottari", { ...birth, levels: 1 }),
  post("/v1/yogas", birth),
  post("/v1/dosha/mangal", birth),
]);

// One document your template renders - and the version that produced it.
const report = {
  engine_version: d1.meta.engine_version,
  summary: {
    lagna: details.data.ascendant.sign,
    moon_sign: details.data.moon_sign,
    nakshatra: `${details.data.nakshatra} pada ${details.data.nakshatra_pada}`,
  },
  d1: d1.data.planets.map((p) => [p.name, p.sign, p.house]),
  d9_lagna: d9.data.ascendant_sign,
  mahadashas: dasha.data.mahadasha.map((m) => [m.lord, m.start.slice(0, 10), m.end.slice(0, 10)]),
  yogas_present: yogas.data.yogas.filter((y) => y.present).map((y) => y.name),
  mangal_dosha: mangal.data.present,
};

console.error(JSON.stringify(report.summary), "|", report.yogas_present.length, "yogas |",
  "mangal:", report.mangal_dosha, "| d9 lagna:", report.d9_lagna, "| engine", report.engine_version);

const rows = report.mahadashas.map(([l, s, e]) => `<tr><td>${l}</td><td>${s}</td><td>${e}</td></tr>`).join("");
console.log(`<!doctype html><meta charset="utf-8"><title>Kundli</title>
<h1>${report.summary.lagna} lagna, Moon in ${report.summary.moon_sign}</h1>
<p>Nakshatra: ${report.summary.nakshatra}</p>
<h2>Vimshottari mahadashas</h2><table>${rows}</table>
<h2>Yogas present</h2><p>${report.yogas_present.join(", ")}</p>
<footer>Computed by engine ${report.engine_version}</footer>`);

stderr:

text
{"lagna":"Virgo","moon_sign":"Sagittarius","nakshatra":"Uttara Ashadha pada 1"} | 10 yogas | mangal: false | d9 lagna: Gemini | engine 1.2.1

stdout (kundli.html):

html
<!doctype html><meta charset="utf-8"><title>Kundli</title>
<h1>Virgo lagna, Moon in Sagittarius</h1>
<p>Nakshatra: Uttara Ashadha pada 1</p>
<h2>Vimshottari mahadashas</h2><table><tr><td>Sun</td><td>1973-04-24</td><td>1979-04-04</td></tr><tr><td>Moon</td><td>1979-04-04</td><td>1989-04-04</td></tr><tr><td>Mars</td><td>1989-04-04</td><td>1996-04-04</td></tr><tr><td>Rahu</td><td>1996-04-04</td><td>2014-04-04</td></tr><tr><td>Jupiter</td><td>2014-04-04</td><td>2030-04-04</td></tr><tr><td>Saturn</td><td>2030-04-04</td><td>2049-04-04</td></tr><tr><td>Mercury</td><td>2049-04-04</td><td>2066-04-04</td></tr><tr><td>Ketu</td><td>2066-04-04</td><td>2073-04-04</td></tr><tr><td>Venus</td><td>2073-04-04</td><td>2093-04-04</td></tr><tr><td>Sun</td><td>2093-04-04</td><td>2099-04-04</td></tr></table>
<h2>Yogas present</h2><p>Vesi, Vasi, Ubhayachari, Sunafa, Sankha, Raja Yoga, Kaala Sarpa, Vimala, Paasha, Shakata</p>
<footer>Computed by engine 1.2.1</footer>

levels: 1 keeps the dasha response to the nine-to-ten mahadashas a report table needs; ask for levels: 2 or more only if you print antardashas, since the payload grows ninefold per level.

From HTML to PDF

Producing the PDF is a rendering step in your stack, not an API call. The usual options, in rising order of effort:

  • Let the browser do it. Serve the HTML with a print stylesheet (@page { size: A4; margin: 16mm }) and a Download button that calls window.print().
  • Headless Chromium on your server (Playwright or Puppeteer page.pdf()), when the PDF must be emailed or stored.
  • A PDF library (pdfkit, ReportLab) when you need exact page control and no browser in the container.

Draw the D1 and D9 boxes with the renderer from North or South Indian chart - the varga response has the same sign and house per planet.

Store the document, not the calls

  • Save the assembled JSON with its engine_version and birth input. Re-rendering a stored report then costs zero calls, and if a customer asks why two copies differ, the version answers it.
  • If one call fails, fail the report. A kundli with a silently missing section is worse than an error page; retry the whole set later.
  • Escape anything user-supplied (names, places) before you put it in HTML. Values from the API are fixed enumerations and dates.
  • The interpretation object that some endpoints add next to data is optional prose; this recipe ignores it and writes its own copy.

Questions

What do I end up with?
A kundli document (JSON + HTML) assembled from six parallel calls. The code is in Node.js.
Which endpoints does this recipe call, and in what order?
6 endpoints, in this order: Birth Details (Rashi, Nakshatra, Lagna) (POST /v1/birth-details), then Birth Chart (Kundli) (POST /v1/charts/birth), then Divisional Charts (Navamsa, D1-D60) (POST /v1/charts/varga), then Vimshottari Dasha (POST /v1/dasha/vimshottari), then Yoga Detection (POST /v1/yogas), then Mangal Dosha (Manglik) (POST /v1/dosha/mangal).