Getting started

You need three things: an API key, your club's id, and the base URL.

Which key

There are two kinds, and the prefix tells you which you hold.

KeyLooks likeUse itRule
Publishablelb_pk_...in a web page, in the browserworks only from the website addresses (origins) listed for it
Serverlb_sk_...on a server, in a script, in an AI agentnever in a web page

A publishable key is safe to put in your page's source: it is only accepted from your own site. A server key has no such protection, so anyone who sees it can use it. Read Keys before you deploy.

Your first call

Send the key in the X-Api-Key header. The club summary is the simplest call:

curl https://api.lovebowls.co.uk/v1/clubs/CLUB_ID \
  -H "X-Api-Key: $LB_KEY"
{
  "id": "52e5435c-8b5e-4e0d-abbb-6cb90b66f3b6",
  "name": "lovebowls demo",
  "timeZone": "Europe/London",
  "teams": [{ "id": "A", "name": "A team" }],
  "season": { "start": "2027-01-01T00:00:00.000Z", "end": "2028-01-01T00:00:00.000Z" }
}

Then the club's fixtures for the current season:

curl "https://api.lovebowls.co.uk/v1/clubs/CLUB_ID/fixtures?limit=5" \
  -H "X-Api-Key: $LB_KEY"

The response is { "items": [...], "nextCursor": ... }. See Fixtures for the fields and filters and Paging for the rest of the pages.

With the JavaScript SDK

The SDK is @lovebowls/api, for browsers, Node and other runtimes with fetch.

npm i @lovebowls/api
import { LovebowlsClient, LovebowlsApiError } from "@lovebowls/api";

const lb = new LovebowlsClient({ apiKey: process.env.LB_KEY });

const club = await lb.getClub("CLUB_ID");
console.log(club.name, club.timeZone);

const { items, nextCursor } = await lb.listFixtures("CLUB_ID", { limit: 5 });
for (const fixture of items) console.log(fixture.start, fixture.competition.name, fixture.opponent);

try {
  await lb.getFixture("CLUB_ID", "no-such-id");
} catch (error) {
  if (error instanceof LovebowlsApiError) console.log(error.status, error.code, error.requestId);
  else throw error;
}

In a web page, load it from a CDN as a module instead:

<script type="module">
  import { LovebowlsClient } from "https://cdn.jsdelivr.net/npm/@lovebowls/api@0.5.0/+esm";
  const lb = new LovebowlsClient({ apiKey: "lb_pk_..." }); // a publishable key only
</script>

new LovebowlsClient({ apiKey, baseUrl?, fetch? }) takes an optional baseUrl and an optional fetch implementation, for tests and older runtimes. An empty apiKey throws a TypeError straight away.

If it fails

Every error has a stable code. The first ones you are likely to meet:

The full list is in Errors.