Session 6
Introduction to APIs
Hodel Taught by Tobias Hodel.
In this session
- What an API is, and why it matters for research
- Calling the Zotero API — including setting up a token
- APIs of cultural heritage institutions
APIs, concretely
- Client, server, request, response
- HTTP methods, status codes, and what a
404versus a403is telling you - Endpoints, parameters, pagination
- JSON and XML as response formats; reading a JSON structure without panicking
- Authentication: API keys, tokens, and how not to publish yours
- Rate limits, and being a well-behaved client
- Tools: the browser,
curl, Postman, and Python’srequests
An API key in a Git repository is a key on the open internet, and deleting it later does not help — the history keeps it. Use an .env file, and put .env in .gitignore. We set this up together.
The Zotero API
Your bibliography, programmatically:
- Create an API key in your Zotero settings
- Find your user or group library ID
- Retrieve items, collections and tags
- Request different formats — JSON, BibTeX, CSL JSON
- Paginate through a library larger than one response
This is the direct route from your Zotero library to the website you are building in the Intro’s assignment: the site pulls the bibliography rather than you pasting it.
APIs of cultural heritage institutions
A survey of what is actually available, and in what shape:
- IIIF — the Image API and the Presentation API; why every serious digitisation project uses it
- OAI-PMH — metadata harvesting, still the backbone of library and archive exchange
- SPARQL endpoints — Wikidata and others, following on from Session 5
- Institutional REST APIs, and their very variable quality
A collected list of examples: https://pad.dsl.unibe.ch/p/resed-api-20260129#/
Exercise
Pick an institution relevant to your topic, find its API, retrieve twenty records, and save them as a local file. Then write down, in three sentences, what the API refused to give you.