Continuing to look for good ways to get data from Wikipedia, I’m also exploring the WikidataQuery API. I couldn’t make anything happen with the old Wikidata Query editor, but the newer Autolist tool was nicer than tweaking browser urls.
Tag: wikidata
Using the Wikidata API
I recently used Wikidata to retrieve dates of birth and death for a set of people. Figuring out the Wikidata API wasn’t obvious, and the documentation was circular or broken, but here’s what I ended up doing.
First, discover the entity ID:
https://www.wikidata.org/w/api.php?action=wbsearchentities&search=Maurice%20Sendak&language=en
While it’s possible to query the ID directly for date of birth (P569) and date of death (P570) properties, I couldn’t figure out how to request two properties in one request. Singularly, this will retrieve a record for Date of Birth:
https://www.wikidata.org/w/api.php?action=wbgetclaims&entity=Q314771&property=P569
Dropping the property argument and sending one request for the entire entity is probably faster, and filtering for specific properties is easily done afterwards.
A list of Wikidata’s cryptic property ids is here: Wikidata:List of properties/all (that’s a lot better than wading through the Wikidata Query editor
All queries should probably include &format=json&callback=foo as well.
Overall, this felt pretty clumsy. I ended up doing a lot of manual copy-and-paste to fix missing data.