-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
57 lines (48 loc) · 1.75 KB
/
example.js
File metadata and controls
57 lines (48 loc) · 1.75 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
57
/**
* Kundli matching API example (JavaScript SDK, ESM)
* Calculates Guna Milan (Ashtakoota) compatibility score for two birth charts.
* Endpoint: POST /vedic-astrology/compatibility (calculateGunMilan)
* Docs: https://roxyapi.com/api-reference
*/
import { createRoxy } from '@roxyapi/sdk';
const roxy = createRoxy(process.env.ROXY_API_KEY);
// Step 1: geocode each birth city - never hardcode coordinates
const { data: loc1, error: locErr1 } = await roxy.location.searchCities({ query: { q: 'New Delhi' } });
if (locErr1) throw new Error(locErr1.error);
const p1 = loc1.cities[0]; // { latitude, longitude, timezone }
const { data: loc2, error: locErr2 } = await roxy.location.searchCities({ query: { q: 'Mumbai' } });
if (locErr2) throw new Error(locErr2.error);
const p2 = loc2.cities[0];
// Step 2: 36-point Guna Milan compatibility
const { data, error } = await roxy.vedicAstrology.calculateGunMilan({
body: {
person1: {
date: '1990-07-04',
time: '10:12:00',
latitude: p1.latitude,
longitude: p1.longitude,
timezone: p1.timezone,
},
person2: {
date: '1992-03-15',
time: '08:30:00',
latitude: p2.latitude,
longitude: p2.longitude,
timezone: p2.timezone,
},
},
});
if (error) {
console.error('API error:', error.error);
process.exit(1);
}
console.log(`Guna Milan Score: ${data.total}/${data.maxScore} (${data.percentage.toFixed(1)}%)`);
console.log(`Compatible: ${data.isCompatible}`);
console.log(`Recommendation: ${data.recommendation}`);
if (data.doshas.length > 0) {
console.log(`Active Doshas: ${data.doshas.join(', ')}`);
}
console.log('\nBreakdown:');
for (const koota of data.breakdown) {
console.log(` ${koota.category}: ${koota.score}/${koota.maxScore} - ${koota.description}`);
}