Wikidata:REST API
Overview
[edit]The Wikibase REST API is an OpenAPI-based interface that allows users to interact with, retrieve and edit Items, Properties and Statements on Wikibase instances -- including of course Wikidata. For more information about REST, see the Wikipedia entry on representational state transfer.
How to use the API
[edit]You can access the Wikibase API on Wikidata using the base URL: https://www.wikidata.org/w/rest.php/wikibase/v1
- Set up authentication.
- Consult the OpenAPI Swagger documentation for specific instructions on each call.
You can also take a look at the Wikibase developer documentation.
The Wikibase REST API is covered by Wikidata's Stable Interface Policy.
Functionality
[edit]You'll find all the calls in our new REST API, including examples, in our OpenAPI Swagger documentation.
We're constantly working on improving the functionality of the API. To have your say in that changing functionality, consider adding your feedback on the talk page or make a ticket on the Phabricator board.
Error messages
[edit]The Wikibase REST API throws informative error messages, documented for each call in detail in the Responses section of the OpenAPI documentation.
Rate limits
[edit]As does any public API, the Wikibase REST API on Wikidata has certain rate limits in place to prevent misuse and abuse.
Because the Wikibase REST API uses the same underlying classes as the Action API, rate limiting happens according to the same rules and using the same setting, $wgRateLimits
. See the Action API rate-limiting documentation for more details.
Why should I use the Wikibase REST API?
[edit]The REST API is tailored to the Wikibase data model, and it solves a number of existing issues that are easier to solve with REST.
- For Item data, the REST API uses Statements instead of claims.
- Cleaner, flatter structure in response data.
- A number of improvements in how Statement data and metadata are presented.
The REST API conforms to modern industry standards, as opposed to the Wikibase calls in the Action API. Developers familiar with REST APIs will find the Wikibase REST API much easier to use.
Wikibase REST API is versioned (see info.version
field in the Open API document), so functionality stays stable. Breaking changes are generally avoided, but in case of a breaking change it will be indicated in the change of the version in the API URL.
Check out our comparison of old and new functionality to get a feel for the contrast between the Action and REST API.
Libraries
[edit]- Wikidatum, a third-party Ruby gem, is available for interacting with the Wikibase REST API.
- wikibase-patcher, a minimum Wikibase REST API implementation in Python.
- wikibase-rest-api-client, Wikibase REST API client on pypi generated from the OpenApi Spec
Wikibase: How to enable the API
[edit]To enable the REST API on an instance of Wikibase, add the following line to your LocalSettings.php
:
$wgRestAPIAdditionalRouteFiles[] = 'extensions/Wikibase/repo/rest-api/routes.json';
See also
[edit]- Wikidata:Data access for other ways to access Wikidata's data