Live example: visitor
Each section below is one call to the lovebowls API: the code to make it, in the language you choose, and the live answer from the demo club. Nobody needs to log in. For the member calls, see the member example.
Before you start
Every call sends an API key in the X-Api-Key header. The key decides which tab fits your code:
- SDK and fetch run in a web page. They use a publishable key
(
lb_pk_...), which works only from the addresses on its list. It is safe to put in your page. - cURL and Python run on a server. They use a server key
(
lb_sk_...) from the environment variableLB_API_KEY. Never put a server key in a page.
See Keys. Install the SDK from npm, or import it from jsDelivr in a page with no build step:
npm i @lovebowls/api
<script type="module">
import { LovebowlsClient } from "https://cdn.jsdelivr.net/npm/@lovebowls/api@0.5.0/+esm";
</script>
The code uses the demo club's id. Put your own club's id in its place.
Club
GET /v1/clubs/{clubId}. The club's name, its time zone, its teams and the dates of the current season. Show
every date and time in the club's timeZone: the API sends UTC.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const club = await lb.getClub(CLUB_ID);
console.log(club.name, club.timeZone);
for (const team of club.teams) console.log(team.id, team.name);
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}`, { headers });
if (!res.ok) throw new Error((await res.json()).code); // problem+json with a stable code
const club = await res.json();
console.log(club.name, club.timeZone);
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}", headers=headers, timeout=10)
r.raise_for_status()
club = r.json()
print(club["name"], club["timeZone"])
Live result
Loading...
Response JSON
Competitions
GET /v1/clubs/{clubId}/competitions. Every competition the club plays, with its colours. The list is not paged.
Add kind=match or kind=event to get one kind only.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const { items } = await lb.listCompetitions(CLUB_ID);
for (const c of items) console.log(c.name, c.kind, c.colour);
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}/competitions`, { headers });
if (!res.ok) throw new Error((await res.json()).code);
const { items } = await res.json();
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/competitions" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}/competitions", headers=headers, timeout=10)
r.raise_for_status()
for c in r.json()["items"]:
print(c["name"], c["kind"])
Live result
Loading...
Response JSON
Fixtures this season
GET /v1/clubs/{clubId}/fixtures. Matches and club events, oldest first, with results once there are some.
With no from and to, the range is the current season. The list is paged: send each page's
nextCursor back as cursor until it is null. The SDK's iterateFixtures
does that for you. See Fixtures and leagues and Paging.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const club = await lb.getClub(CLUB_ID); // for its time zone
const when = new Intl.DateTimeFormat("en-GB", { dateStyle: "medium", timeStyle: "short", timeZone: club.timeZone });
for await (const f of lb.iterateFixtures(CLUB_ID)) { // every page of the current season
const title = f.kind === "event" ? f.eventName : `${f.venue === "home" ? "v" : "at"} ${f.opponent}`;
console.log(when.format(new Date(f.start)), title, f.result?.text ?? "");
}
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const fixtures = [];
let cursor = null;
do {
const query = new URLSearchParams({ limit: "100" });
if (cursor) query.set("cursor", cursor);
const res = await fetch(`${API}/clubs/${CLUB_ID}/fixtures?${query}`, { headers });
if (!res.ok) throw new Error((await res.json()).code);
const page = await res.json();
fixtures.push(...page.items);
cursor = page.nextCursor;
} while (cursor);
# the first page; repeat with &cursor=<nextCursor> until nextCursor is null
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/fixtures?limit=100" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
fixtures, cursor = [], None
while True:
params = {"limit": 100, **({"cursor": cursor} if cursor else {})}
r = requests.get(f"{API}/clubs/{CLUB_ID}/fixtures", headers=headers, params=params, timeout=10)
r.raise_for_status()
page = r.json()
fixtures += page["items"]
cursor = page["nextCursor"]
if cursor is None:
break
Live result
Loading...
Response JSON (every page, joined)
League table
GET /v1/leagues/{leagueId}. A league and its table. A league has no club id in its path: the league id is
enough. Get the id from lovebowls.
import { LovebowlsClient } from "@lovebowls/api";
const LEAGUE_ID = "..."; // your league's id
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const league = await lb.getLeague(LEAGUE_ID);
for (const row of league.table) console.log(row.position, row.teamName, row.played, row.points);
const API = "https://api.lovebowls.co.uk/v1";
const LEAGUE_ID = "..."; // your league's id
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/leagues/${LEAGUE_ID}`, { headers });
if (!res.ok) throw new Error((await res.json()).code);
const league = await res.json();
curl "https://api.lovebowls.co.uk/v1/leagues/$LEAGUE_ID" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
LEAGUE_ID = "..." # your league's id
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/leagues/{LEAGUE_ID}", headers=headers, timeout=10)
r.raise_for_status()
for row in r.json()["table"]:
print(row["position"], row["teamName"], row["points"])
Live result
Loading...
Response JSON
News
GET /v1/clubs/{clubId}/news. The club's current news, newest first, paged like fixtures. A visitor gets the
public articles. A member of the club also gets the members-only articles: see the
member example and News, honours and trophies.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const page = await lb.listNews(CLUB_ID, { limit: 5 }); // one page
for (const n of page.items) console.log(n.showFrom, n.title, n.summary);
// the next page: lb.listNews(CLUB_ID, { limit: 5, cursor: page.nextCursor })
// every article: for await (const n of lb.iterateNews(CLUB_ID)) { ... }
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}/news?limit=5`, { headers });
if (!res.ok) throw new Error((await res.json()).code);
const { items, nextCursor } = await res.json(); // send nextCursor back as ?cursor= for the next page
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/news?limit=5" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}/news", headers=headers, params={"limit": 5}, timeout=10)
r.raise_for_status()
for n in r.json()["items"]:
print(n["showFrom"], n["title"])
Live result
Loading...
Response JSON (the last page)
News article
GET /v1/clubs/{clubId}/news/{articleId}. One article, with its body as bodyHtml and its
attachments. The API has already sanitised bodyHtml: you can insert it as it is. This page's
Content-Security-Policy forbids inline styles and remote pictures, so its script turns the body's styled spans into
strong, em and u, and shows a picture's alt text instead of the picture. See
the sanitised body. Choose an article in News to show it here.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const article = await lb.getNewsArticle(CLUB_ID, articleId); // an id from listNews
document.querySelector("#title").textContent = article.title;
document.querySelector("#body").innerHTML = article.bodyHtml; // sanitised by the API
for (const file of article.attachments) console.log(file.name, file.url);
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}/news/${articleId}`, { headers });
if (res.status === 404) { /* news_not_found: gone, out of its window, or members-only */ }
else if (!res.ok) throw new Error((await res.json()).code);
const article = await res.json();
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/news/$ARTICLE_ID" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}/news/{article_id}", headers=headers, timeout=10)
r.raise_for_status()
article = r.json()
print(article["title"], len(article["attachments"]), "attachments")
Live result
Loading...
Response JSON
Honours board
GET /v1/clubs/{clubId}/honours. The honours board, newest year first, with the winners of each title. A
winner who has left the club has kind: "formerMember" and no name.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const { items } = await lb.listHonours(CLUB_ID);
for (const h of items) {
const winners = h.winners.map((w) => (w.kind === "formerMember" ? "a former member" : w.name));
console.log(h.year, h.title, winners.join(", "));
}
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}/honours`, { headers });
if (!res.ok) throw new Error((await res.json()).code);
const { items } = await res.json();
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/honours" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}/honours", headers=headers, timeout=10)
r.raise_for_status()
for h in r.json()["items"]:
names = [w["name"] or "a former member" for w in h["winners"]]
print(h["year"], h["title"], ", ".join(names))
Live result
Loading...
Response JSON
Life members
GET /v1/clubs/{clubId}/life-members. The club's life members, with a flag for its founders.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const { items } = await lb.listLifeMembers(CLUB_ID);
for (const m of items) console.log(m.name, m.founder ? "(founder)" : "");
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}/life-members`, { headers });
if (!res.ok) throw new Error((await res.json()).code);
const { items } = await res.json();
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/life-members" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}/life-members", headers=headers, timeout=10)
r.raise_for_status()
for m in r.json()["items"]:
print(m["name"], "(founder)" if m["founder"] else "")
Live result
Loading...
Response JSON
Trophies
GET /v1/clubs/{clubId}/trophies. The club's trophies, without their winners. Choose a trophy to see its
winners in Trophy winners.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const { items } = await lb.listTrophies(CLUB_ID);
for (const t of items) console.log(t.id, t.name, t.knownAs ?? "", t.firstYear ?? "");
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}/trophies`, { headers });
if (!res.ok) throw new Error((await res.json()).code);
const { items } = await res.json();
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/trophies" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}/trophies", headers=headers, timeout=10)
r.raise_for_status()
for t in r.json()["items"]:
print(t["id"], t["name"])
Live result
Loading...
Response JSON
Trophy winners
GET /v1/clubs/{clubId}/trophies/{trophyId}. One trophy with every year, newest first. A year with
awarded: false had no winner.
import { LovebowlsClient } from "@lovebowls/api";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // your publishable key
const trophy = await lb.getTrophy(CLUB_ID, trophyId); // an id from listTrophies
for (const y of trophy.years) {
const winners = y.winners.map((w) => (w.kind === "formerMember" ? "a former member" : w.name));
console.log(y.year, y.awarded ? winners.join(", ") : "Not awarded");
}
const API = "https://api.lovebowls.co.uk/v1";
const CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6";
const headers = { "X-Api-Key": "lb_pk_..." }; // your publishable key
const res = await fetch(`${API}/clubs/${CLUB_ID}/trophies/${trophyId}`, { headers });
if (!res.ok) throw new Error((await res.json()).code); // 404 trophy_not_found
const trophy = await res.json();
curl "https://api.lovebowls.co.uk/v1/clubs/52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6/trophies/$TROPHY_ID" \
-H "X-Api-Key: $LB_API_KEY"
import os, requests
API = "https://api.lovebowls.co.uk/v1"
CLUB_ID = "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6"
headers = {"X-Api-Key": os.environ["LB_API_KEY"]} # a server key
r = requests.get(f"{API}/clubs/{CLUB_ID}/trophies/{trophy_id}", headers=headers, timeout=10)
r.raise_for_status()
for y in r.json()["years"]:
print(y["year"], [w["name"] for w in y["winners"]] if y["awarded"] else "Not awarded")
Live result
Loading...
Response JSON
How this page works
The page holds a publishable key in a <meta name="lb-key"> tag. That key works only from this site's
own address, so it is safe to show. The page is plain HTML and two small scripts:
visitor.js makes the calls and
ui.js draws the code tabs and the copy buttons. Read them and copy what you need.