Integration GuideReactNext.jsPythonVimshottari

Dasha API Integration Guide
React · Next.js · Python · PHP

Working code examples for every stack. Add Vimshottari Mahadasha timelines, current period display, and full sequence data to your astrology app in minutes.

Get Free API Key →Dasha API Overview

1. Basic Fetch (JavaScript)

dasha.js
// Basic Dasha fetch — Node.js / browser fetch
async function getDasha(birthData) {
  const { dob, tob, lat, lon, tz, apiKey } = birthData
  const url = new URL(
    'https://vedintelastroapi.com/api/v1/dashas/current-mahadasha-full'
  )
  url.searchParams.set('api_key', apiKey)
  url.searchParams.set('dob', dob)   // DD/MM/YYYY
  url.searchParams.set('tob', tob)   // HH:MM (24hr)
  url.searchParams.set('lat', String(lat))
  url.searchParams.set('lon', String(lon))
  url.searchParams.set('tz', String(tz))

  const res = await fetch(url.toString())
  if (!res.ok) throw new Error(`HTTP ${res.status}`)

  const data = await res.json()
  if (data.status !== 200) throw new Error(data.error ?? 'API error')

  return data.response
}

// Usage
const dasha = await getDasha({
  apiKey: 'vai_YOUR_KEY',
  dob: '15/06/1990', tob: '08:30',
  lat: 19.0760, lon: 72.8777, tz: 5.5,
})
// dasha.mahadasha     → { planet: "Jupiter", start: "2018-01-15", end: "2034-01-15" }
// dasha.antardasha    → { planet: "Saturn",  start: "2024-06-01", end: "2026-12-31" }
// dasha.pratyantardasha → { planet: "Mercury" ... }

2. React Hook + Component

useDasha.jsx
// React hook: useDasha
import { useState, useEffect } from 'react'

function useDasha(birthData) {
  const [dasha, setDasha]   = useState(null)
  const [loading, setLoading] = useState(true)
  const [error, setError]   = useState(null)

  useEffect(() => {
    if (!birthData) return
    setLoading(true)

    const params = new URLSearchParams({
      api_key: process.env.NEXT_PUBLIC_VAI_KEY,
      dob: birthData.dob, tob: birthData.tob,
      lat: birthData.lat, lon: birthData.lon, tz: birthData.tz,
    })

    fetch(`/api/v1/dashas/current-mahadasha-full?${params}`)
      .then(r => r.json())
      .then(data => {
        if (data.status === 200) setDasha(data.response)
        else setError(data.error ?? 'Unknown error')
      })
      .catch(err => setError(err.message))
      .finally(() => setLoading(false))
  }, [birthData?.dob, birthData?.tob])

  return { dasha, loading, error }
}

// Component
function DashaWidget({ birthData }) {
  const { dasha, loading, error } = useDasha(birthData)

  if (loading) return <p>Loading dasha periods...</p>
  if (error)   return <p>Error: {error}</p>
  if (!dasha)  return null

  return (
    <div className="dasha-widget">
      <div className="mahadasha">
        <h3>Mahadasha: {dasha.mahadasha.planet}</h3>
        <p>{dasha.mahadasha.start} → {dasha.mahadasha.end}</p>
      </div>
      <div className="antardasha">
        <h4>Antardasha: {dasha.antardasha.planet}</h4>
        <p>{dasha.antardasha.start} → {dasha.antardasha.end}</p>
      </div>
    </div>
  )
}

3. Next.js API Proxy (keep key server-side)

src/app/api/dasha/route.ts
// Next.js API proxy — keep your key server-side
// src/app/api/dasha/route.ts
import { NextRequest, NextResponse } from 'next/server'

export async function GET(request: NextRequest) {
  const { searchParams } = request.nextUrl
  const dob = searchParams.get('dob')
  const tob = searchParams.get('tob')
  const lat = searchParams.get('lat')
  const lon = searchParams.get('lon')
  const tz  = searchParams.get('tz')

  if (!dob || !tob || !lat || !lon || !tz) {
    return NextResponse.json({ error: 'Missing params' }, { status: 400 })
  }

  const upstream = await fetch(
    `https://vedintelastroapi.com/api/v1/dashas/current-mahadasha-full` +
    `?api_key=${process.env.VAI_API_KEY}&dob=${dob}&tob=${tob}` +
    `&lat=${lat}&lon=${lon}&tz=${tz}`
  )
  const data = await upstream.json()

  // Cache at edge for 1 hour — natal data doesn't change
  return NextResponse.json(data, {
    headers: { 'Cache-Control': 's-maxage=3600, stale-while-revalidate' }
  })
}

4. Python

dasha.py
# Python: full Vimshottari sequence + current period
import requests
from datetime import datetime

VAI_KEY = "vai_YOUR_KEY"
BASE    = "https://vedintelastroapi.com/api/v1"

birth = dict(
  api_key=VAI_KEY, dob="15/06/1990", tob="08:30",
  lat=19.0760, lon=72.8777, tz=5.5
)

# Get all 9 Mahadasha periods from birth
sequence = requests.get(f"{BASE}/dashas/mahadasha", params=birth).json()
for period in sequence["response"]:
    print(f"{period['planet']:10} | {period['start']} → {period['end']}")

# Get current full stack
current = requests.get(f"{BASE}/dashas/current-mahadasha-full", params=birth).json()
r = current["response"]
print(f"\nCurrent: {r['mahadasha']['planet']} / {r['antardasha']['planet']}")
print(f"Remaining calls: {current['remaining_api_calls']}")

Dasha Integration — FAQs

Should I call the Dasha API on the server or client side?
Always call it server-side (Node.js, Next.js API routes, Python backend, PHP). This keeps your API key out of the browser. In Next.js, create a /api/dasha proxy route that calls our API using process.env.VAI_API_KEY and forwards the result to the client. Never expose your api_key in frontend JavaScript.
How often does the current Dasha period change?
Mahadasha periods last 6-20 years depending on the planet. Antardasha periods last weeks to ~3 years. You do not need to refresh dasha data frequently. Cache the response at the edge for 1 hour (Cache-Control: s-maxage=3600) or even 24 hours — the period only changes when the Antardasha transitions, which you can compute from the end date in the response.
What does the remaining_api_calls field mean?
After each successful API call, the response includes remaining_api_calls — the number of calls remaining in your monthly quota. When it reaches 0, the API returns 429 Too Many Requests. Build your app to gracefully handle this by checking the field and showing a friendly message rather than breaking the UI.
How do I display a Mahadasha timeline in my app?
Call /dashas/mahadasha to get all 9 planetary periods with start and end dates. Each period object contains planet, start (ISO date), end (ISO date), and duration_years. Use these to render a timeline bar chart or table. Highlight the current period by comparing today's date with the start/end fields. You can call /dashas/antardasha with the current Mahadasha planet to get the sub-period breakdown.
What happens if I pass an invalid date format?
The API validates all input at the boundary. If dob is not in DD/MM/YYYY format, or tob is not HH:MM, the API returns status: 400 with a specific error message. Always validate user input before calling the API — particularly birth year (must be > 1800), and timezone (must be a decimal like 5.5 for IST, not a string like "Asia/Kolkata").
Related Resources
Dasha API Use CaseKundli APIFree Vedic API GuideSwiss Ephemeris Node.js

Start for free. Ship today.

500 free calls/month. All 11 dasha endpoints. No credit card.

Get Your Free API Key →