Trains between two stations
Every train between two Indian Railways stations (nearby stations of the same city included, e.g. NZM for NDLS): number, name and type, boarding and alighting station with platforms, departure, arrival, duration and day offset, distance and average speed, days it runs, classes, indicative fares per class (adult, child, Tatkal; INR), pantry, zone, validity dates and the coach order. Give date to keep only the trains running that day. Find station codes with /indian-rail/v1/stations.
Every response includes credits_used: the credits this call cost.
Parameters
| name | type | description |
|---|---|---|
fromrequired | string | Boarding station code, e.g. NDLS (New Delhi), CSMT, HWH, SBC, MAS. Example: NDLS |
torequired | string | Destination station code, e.g. BCT (Mumbai Central). Example: BCT |
date | string | Journey date (YYYY-MM-DD): only trains that run from the boarding station on that day, each marked runs_on_date. |
class | 1A | 2A | 3A | CC | FC | SL | 2S | 3E | GN | EA | EC | EV | VC | VS | Only trains with this class. |
type | string | Only this train type, e.g. RAJDHANI, SHATABDI, DURONTO, VANDE BHARAT, SUPERFAST, MAIL_EXPRESS, GARIB RATH. |
exact | boolean | true: only trains from exactly from to exactly to (no nearby stations). |
Every endpoint also takes fresh, raw, fields (see lean responses and caching).
Example
curl "https://api.api.sh/indian-rail/v1/trains?from=NDLS&to=BCT" \
-H "x-api-key: $APISH_KEY" import os, requests
res = requests.get(
"https://api.api.sh/indian-rail/v1/trains",
params={"from": "NDLS", "to": "BCT"},
headers={"x-api-key": os.environ["APISH_KEY"]},
timeout=120,
)
res.raise_for_status()
data = res.json() const url = new URL("https://api.api.sh/indian-rail/v1/trains");
url.searchParams.set("from", "NDLS");
url.searchParams.set("to", "BCT");
const res = await fetch(url, { headers: { "x-api-key": process.env.APISH_KEY } });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const data = await res.json(); Response
A JSON object with the fields described above, plus raw (the source's own data), cached, fetched_at and credits_used. Errors return {"success": false, "error": "…"} with the HTTP status (see errors). A lookup that ran but found nothing (404) costs the price above; refused calls and errors on our side are free (what's charged).