Wikidata and Wikidata API - bounswe/bounswe2024group8 GitHub Wiki
Wikidata
Wikidata is a free, collaborative, multilingual knowledge base operated by the Wikimedia Foundation. It serves as a central storage for the structured data of its Wikimedia sister projects including Wikipedia, Wikivoyage, Wiktionary, Wikisource, and others. Wikidata aims to provide a common source of data that can be used by Wikimedia projects and beyond, in a way that is accessible and editable by both humans and machines. It includes information on a wide range of topics, from historical events and figures to scientific concepts and geographical data.
Wikidata REST API
Base url: https://www.wikidata.org/w/rest.php/wikibase/v0
Swagger: https://doc.wikimedia.org/Wikibase/master/js/rest-api/
To make authenticated requests against the Wikibase REST API for Wikidata, you must first set up an OAuth 2.0 client (formerly known as "consumer").
Once the OAuth 2.0 is set up you can start using this REST API
Wikidata API
Wikidata API VS Wikipedia API
While the Wikipedia API allows you to query the content that you find on the actual Wikipedia page, the Wikidata API allows you to query the data behind that is used to build content across the MediaWiki organisation (wikitravel, wikipedia, wikispecies, etc.).
So, with the Wikidata API, you can, in a way query the Wikipedia content, but with wikipedia, you may not be able to query some of the data in wikidata.
You can test some endpoints in this Sandbox: https://www.wikidata.org/wiki/Special:ApiSandbox#action=wbsearchentities&search=alphabet&language=en
Example request: https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&search=Google&language=en
Two main action types:
Wbsearchentities:
The wbsearchentities searches for entities using labels and aliases. This helps you to discover the entity ID using free text. For example, using the search term “Google” to find that it’s entity ID is Q9366.
Wbgetentities:
The wbgetentities action helps you get the data for the Wikibase entities for which you know the ID. This helps you query all the data available for a given wikidata ID. The wikidata ID is either found with the Wbsearchentities API, or in the URL or the title of the Wikidata page.
The Wikidata SPARQL API
Also there is a second way of of getting the needed query in API: This API lets you access Wikidata intelligently. You can formulate complex queries by specifying constraints on the entities and properties. For example, if you wanted to fetch all entities named Bond but only if they refer to human beings, you can use the following query:
Queries can be tested here: https://query.wikidata.org/