Find works
Three ways to find works with a pub key: look up one work, browse the whole collection, and search for words.
When to use what?
| You want to … | Use |
|---|---|
| fetch one specific work | GET /api/v1/objects/{nmId} |
| go through works page by page | GET /api/v1/objects (browse) |
| find works where a word appears in the title, artist name, object name, technique or keywords | GET /api/v1/objects/text-search |
| find works that resemble a description ("horse grazing") | Semantic search (ext) |
Think of text search as a search in the catalogue: it finds the words that are there. Semantic search finds images that resemble the description, even when the words are not in the catalogue.
Look up one work
GET https://api.nasjonalmuseet.no/api/v1/objects/NG.M.00939
nmId is not case-sensitive: ng.m.00939 gives the same work. Use the nmId from the
response from then on. 404 means that the work does not exist or is not published.
Browse the collection
GET /api/v1/objects gives the works page by page, with page and resultsPerPage (up to 200,
default 50).
import os import requests
API = "https://api.nasjonalmuseet.no/api/v1" headers = {"X-API-Key": os.environ["NM_API_KEY"]}
page = 1 while page <= 3: # in practice: until data is empty r = requests.get(f"{API}/objects", params={"page": page, "resultsPerPage": 50, "lang": "en"}, headers=headers, timeout=60) r.raise_for_status() response = r.json() if not response["data"]: break print(f"page {page}: {len(response['data'])} works of {response['totalResults']}") page += 1
The response has totalResults (the number of published works) and data. Continue until data is empty.
The whole dataset
The API is made for look-ups and search, not for downloading the whole collection. If you need the whole dataset, get in touch at api@nasjonalmuseet.no and we will find a better solution.
Search for words
GET /api/v1/objects/text-search?q=… searches titles, artist names, inventory numbers,
object names, object types, keywords, materials, techniques and dates. The search tolerates
typos and finds word beginnings ("vinterland" finds "vinterlandskap"). The hits are
sorted by relevance, 20 per page by default (resultsPerPage up to 100).
curl -s -G -H "X-API-Key: $NM_API_KEY" \ "https://api.nasjonalmuseet.no/api/v1/objects/text-search" \ --data-urlencode "q=winter landscape" -d resultsPerPage=5 -d lang=en
import os import requests
API = "https://api.nasjonalmuseet.no/api/v1" headers = {"X-API-Key": os.environ["NM_API_KEY"]}
r = requests.get(f"{API}/objects/text-search", params={"q": "winter landscape", "resultsPerPage": 5, "lang": "en"}, headers=headers, timeout=30) r.raise_for_status() for work in r.json()["data"]: print(work["nmId"], work["mainTitle"])
const API = "https://api.nasjonalmuseet.no/api/v1"; const headers = { "X-API-Key": process.env.NM_API_KEY };
const url = new URL(${API}/objects/text-search);
url.search = new URLSearchParams({ q: "winter landscape", resultsPerPage: 5, lang: "en" });
const r = await fetch(url, { headers });
if (!r.ok) throw new Error(HTTP ${r.status});
for (const work of (await r.json()).data) console.log(work.nmId, work.mainTitle);
Common mistakes
- Compound words are not split. "fløter" does not find "Tømmerfløtere" (Norwegian for "log drivers"). Search for the whole word, or for its beginning ("tømmerfløt").
- Text search does not find motifs that are not in the catalogue. A painting of a horse without "horse" in the title or keywords is found with semantic search, not with text search.
See also
- Fields: what each field means
- Documentation: all parameters