Tide API code examples
Short examples for the tides.watch Tide API. Each one was run against the live API before it went on this page. Put your key where it says YOUR_KEY; a free key takes a few seconds.
curl
curl -H "x-api-key: YOUR_KEY" "https://api.tides.watch/v1/tides?lat=53.27&lon=-9.06&days=2"
JavaScript: next tide, rising or falling
Works in Node 18 or later and in the browser. Times come back in UTC, so this shows them in a time zone of your choice.
// Next high or low tide, and whether the tide is rising or falling now (Node 18+ or a browser).
const KEY = "YOUR_KEY";
const url = "https://api.tides.watch/v1/tides?lat=53.27&lon=-9.06&days=2";
const res = await fetch(url, { headers: { "x-api-key": KEY } });
const data = await res.json();
if (data.status !== 200) throw new Error(data.error);
const next = data.extremes.find(e => new Date(e.time) > new Date());
const local = new Date(next.time).toLocaleString("en-IE", { timeZone: "Europe/Dublin", weekday: "short", hour: "2-digit", minute: "2-digit" });
console.log(`${data.station.name} (${data.station.distance_km} km away, ${data.station.source})`);
console.log(`Next ${next.type} tide: ${local}, ${next.height} ${data.units}`);
console.log(next.type === "high" ? "The tide is rising." : "The tide is falling.");
console.log(data.attribution);
Python: tide times for the next two days
# Tide times for the next two days, in your computer's time zone (Python 3.9+, pip install requests).
from datetime import datetime
import requests
r = requests.get(
"https://api.tides.watch/v1/tides",
params={"lat": 53.27, "lon": -9.06, "days": 2},
headers={"x-api-key": "YOUR_KEY"},
timeout=20,
)
data = r.json()
if data["status"] != 200:
raise SystemExit(data["error"])
station = data["station"]
print(f'{station["name"]}: {station["distance_km"]} km away, {station["source"]}')
for e in data["extremes"]:
t = datetime.fromisoformat(e["time"].replace("Z", "+00:00")).astimezone()
print(f'{t:%a %H:%M} {e["type"]:<4} {e["height"]} {data["units"]}')
print(data["attribution"])
JavaScript: a tide curve in feet
Use /v1/heights for a smooth curve, and units=ft for feet.
// Tide height every 10 minutes for the next 6 hours, in feet: good for drawing a tide curve.
const res = await fetch("https://api.tides.watch/v1/heights?lat=40.7&lon=-74.01&hours=6&step=10&units=ft",
{ headers: { "x-api-key": "YOUR_KEY" } });
const { station, heights } = await res.json();
console.log(station.name, heights.length, "points, first:", heights[0].time, heights[0].height, "ft");
Good to know
- Times are UTC (ISO 8601, plus
unixseconds). - Heights are in metres unless you ask for
units=ft. Thedatumfield says what they're measured from. - No station nearby? You'll get a
404. Raisemax_km(up to 50), or addmodel=truefor the global tide model. - Show the credit. Display the
attributiontext wherever you show the tides: the data licences require it. - Machine-readable docs: openapi.json works with Postman and code generators.