-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquickstart.mjs
More file actions
56 lines (49 loc) · 2 KB
/
Copy pathquickstart.mjs
File metadata and controls
56 lines (49 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// VedAstro API quickstart — no API key required (free tier, 5 req/min).
// Run: node quickstart.mjs (Node.js 18+ for built-in fetch)
const BASE = "https://api.vedastro.org/api";
/** Call the VedAstro API and unwrap the Status/Payload envelope. */
async function call(method, url, body) {
const res = await fetch(url, {
method,
headers: body ? { "Content-Type": "application/json" } : undefined,
body: body ? JSON.stringify(body) : undefined,
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const json = await res.json();
if (json.Status !== "Pass") throw new Error(`VedAstro API error: ${json.Payload}`);
return json.Payload;
}
async function main() {
// 1. Resolve an address to coordinates.
// NOTE: result is nested under Payload.AddressToGeoLocation — not all
// endpoints nest this way, check the README's verified examples per endpoint.
const payload = await call("POST", `${BASE}/Calculate/AddressToGeoLocation`, {
Address: "mumbai",
Ayanamsa: "RAMAN",
});
console.log("Resolved location:", payload.AddressToGeoLocation);
const birthTime = {
StdTime: "14:30 25/10/1992 +05:30", // HH:MM DD/MM/YYYY +-HH:MM — NOT ISO 8601
Location: { Name: "Mumbai", Latitude: 19.076, Longitude: 72.8777 },
};
// 2. Horoscope predictions — this endpoint returns the array directly as
// Payload (no nested key), unlike AddressToGeoLocation above.
const predictions = await call("POST", `${BASE}/Calculate/HoroscopePredictions`, {
birthTime,
Ayanamsa: "RAMAN",
sortByWeight: true,
});
console.log(`Got ${predictions.length} predictions`);
// 3. Dasa period active at a given check time — nested under Payload.DasaAtTime
const dasa = await call("POST", `${BASE}/Calculate/DasaAtTime`, {
birthTime,
checkTime: { StdTime: "12:00 11/07/2026 +05:30", Location: birthTime.Location },
Ayanamsa: "RAMAN",
levels: 1,
});
console.log("Dasa at check time:", dasa.DasaAtTime);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});