โ† Recipes

Transit alerts: notify users when Saturn changes sign

Transits are the same sky for everyone, so the expensive part runs once per scan, not once per user. Per-user work is a database join you own, and the push is sent by your scheduler at the event time.

You build
A deduplicated alert schedule for Saturn, Jupiter and Rahu, matched to users
Code
Node.js, Python - no SDK, runnable as shown

Updated

One call, every user

POST /v1/transits/events takes a window (from, to), optional planets and step_days, and returns initial_states plus chronologically sorted events. Two years of Saturn, Jupiter and Rahu produced 33 events; the sign changes look like this:

json
{
  "at": "2027-06-03T00:00:00.000Z",
  "planet": "Saturn",
  "longitude": 0.00012053328424599385,
  "sign": "Aries",
  "kind": "sign_change",
  "from_sign": "Pisces",
  "to_sign": "Aries"
}

Other kind values are retrograde_start / _end, combust_start / _end, exalt_start / _end and debilitation_start / _end. Positions are sidereal (Lahiri), like the rest of the Vedic endpoints.

From events to alerts

Keep the sign changes, give each a stable id, and say "re-enters" when a retrograde planet comes back to a sign it occupied earlier in the window - including the sign it started in, which is why initial_states seeds the set. Then match users with whatever rule your product uses; here, users whose stored Moon sign is the sign being entered:

transit-alerts.mjs

Node.js
// transit-alerts.mjs - run from your own scheduler (cron, a queue, a cloud job)
const API = process.env.ASTRONODE_API_URL ?? "https://api.astronode.dev";
const KEY = process.env.ASTRONODE_API_KEY;

// Transits are the same for every user: ONE call covers your whole user base.
const res = await fetch(`${API}/v1/transits/events`, {
  method: "POST",
  headers: { authorization: `Bearer ${KEY}`, "content-type": "application/json" },
  body: JSON.stringify({ from: "2026-12-01", to: "2028-12-31", planets: ["Saturn", "Jupiter", "Rahu"] }),
});
const { data } = await res.json();

// planet -> signs it has occupied in this window, starting with where it is now
const seen = new Map(data.initial_states.map((s) => [s.planet, new Set([s.sign])]));
const alerts = data.events
  .filter((e) => e.kind === "sign_change")
  .map((e) => {
    const entered = seen.get(e.planet) ?? new Set();
    const verb = entered.has(e.to_sign) ? "re-enters" : "enters";
    entered.add(e.to_sign);
    seen.set(e.planet, entered);
    // A stable id makes re-running the job harmless: same event, same id.
    return { id: `${e.planet}:${e.to_sign}:${e.at.slice(0, 10)}`, at: e.at, planet: e.planet, text: `${e.planet} ${verb} ${e.to_sign}`, to: e.to_sign };
  });

// Who gets which alert is your product rule. Here: users whose stored Moon sign
// (from /v1/birth-details at signup) is the sign being entered.
const users = [
  { id: "u1", moon_sign: "Aries" },
  { id: "u2", moon_sign: "Leo" },
  { id: "u3", moon_sign: "Capricorn" },
];
for (const a of alerts) {
  const who = users.filter((u) => u.moon_sign === a.to).map((u) => u.id);
  console.log(`${a.at.slice(0, 10)}  ${a.text.padEnd(28)} ${who.length ? "-> " + who.join(", ") : ""}`);
}

Output:

text
2026-12-06  Rahu enters Capricorn        -> u3
2027-01-25  Jupiter enters Cancer
2027-06-03  Saturn enters Aries          -> u1
2027-06-26  Jupiter re-enters Leo        -> u2
2027-10-21  Saturn re-enters Pisces
2027-11-27  Jupiter enters Virgo
2028-02-24  Saturn re-enters Aries       -> u1
2028-02-29  Jupiter re-enters Leo        -> u2
2028-06-24  Rahu enters Sagittarius
2028-07-25  Jupiter re-enters Virgo
2028-12-27  Jupiter enters Libra

Saturn enters Aries on 3 Jun 2027, retrogrades back into Pisces on 21 Oct 2027 and re-enters Aries on 24 Feb 2028. A naive "Saturn enters Aries" alert would fire twice with the same words; the re-entry label is what keeps your users from thinking it is a bug.

Make the scan idempotent

Run the scan on a schedule - weekly is plenty for slow planets - over a rolling window, and upsert by the stable id. Overlapping windows then add nothing twice. SQLite from the Python standard library shows the pattern:

store_alerts.py

Python 3.9+
# store_alerts.py - upsert upcoming sign changes; a re-run schedules nothing twice
import json, os, sqlite3, urllib.request

API = os.environ.get("ASTRONODE_API_URL", "https://api.astronode.dev")
KEY = os.environ["ASTRONODE_API_KEY"]

db = sqlite3.connect(":memory:")  # your real database
db.execute("CREATE TABLE transit_alert (id TEXT PRIMARY KEY, fire_at TEXT, planet TEXT, to_sign TEXT)")

def sync(frm, to):
    body = {"from": frm, "to": to, "planets": ["Saturn"]}
    req = urllib.request.Request(API + "/v1/transits/events", data=json.dumps(body).encode(),
                                 method="POST", headers={"Authorization": "Bearer " + KEY,
                                                         "Content-Type": "application/json"})
    with urllib.request.urlopen(req) as r:
        events = json.load(r)["data"]["events"]
    before = db.total_changes
    for e in events:
        if e["kind"] == "sign_change":
            db.execute("INSERT OR IGNORE INTO transit_alert VALUES (?, ?, ?, ?)",
                       (f"{e['planet']}:{e['to_sign']}:{e['at'][:10]}", e["at"], e["planet"], e["to_sign"]))
    return db.total_changes - before

print("first run, new rows:", sync("2026-12-01", "2028-12-31"))
print("next week, new rows:", sync("2026-12-08", "2028-12-31"))
for row in db.execute("SELECT fire_at, to_sign FROM transit_alert ORDER BY fire_at"):
    print(row)

Output:

text
first run, new rows: 3
next week, new rows: 0
('2027-06-03T00:00:00.000Z', 'Aries')
('2027-10-21T00:00:00.000Z', 'Pisces')
('2028-02-24T00:00:00.000Z', 'Aries')

Your notifier then selects rows whose fire_at has passed and that have not been sent, joins them to users, and marks them sent. That job, the push provider and the user's notification settings are all yours; the API's part ended with the event list.

Precision and limits

  • Event times are day-granular. The engine samples every step_days (default 1) and stamps an event at the first sample showing the new state, at 00:00 UTC. The real crossing happened during the preceding day. Say "on 3 June", not "at midnight"; or set step_days: 0.25 for six-hour precision at four times the work.
  • Fast planets need finer steps. The Moon changes sign every ~2.5 days; scan it with a smaller step and a shorter window.
  • One call per scan regardless of user count - 52 calls a year for weekly scans. The per-user Moon sign comes from /v1/birth-details, called once at signup and stored.
  • /v1/transits/events needs the Hobby plan.

Questions

What do I end up with?
A deduplicated alert schedule for Saturn, Jupiter and Rahu, matched to users. The code is in Node.js and Python.
Which endpoints does this recipe call, and in what order?
2 endpoints, in this order: Transit Events (Gochar) (POST /v1/transits/events), then Birth Details (Rashi, Nakshatra, Lagna) (POST /v1/birth-details).