Wikidata:REST API

From Wikidata
Revision as of 11:18, 20 June 2024 by DannyS712 (talk | contribs) (Marked this version for translation)
Jump to navigation Jump to search

Overview

The Wikibase REST API is an OpenAPI-based interface that allows users to interact with, retrieve and edit Items 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

You can access the Wikibase API on Wikidata using the base URL: https://www.wikidata.org/w/rest.php/wikibase/v0

  1. Set up authentication.
  2. 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 not yet covered by Wikidata's Stable Interface Policy.

Functionality

You'll find all the calls in our new REST API, including examples, in our OpenAPI Swagger documentation.

We're constantly working on improving and adding functionality to the API; check back often to see what we've added since your last visit. To have your say in that changing functionality, consider adding your feedback on the feedback round talk page.

Error messages

The Wikibase REST API throws informative error messages, documented for each call in detail in the Responses section of the OpenAPI documentation.

API users who have set the bot flag and receive a 403 (rest-write-denied) error likely lack the bot user right. See this Phabricator ticket for more context.

Rate limits

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?

Our new 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.
  • For some examples of issues solved by REST, browse through the REST API workboard on Phabricator.

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.

Versioning! Instead of shoehorning the Wikibase calls into the forever-v1 Action API, the WB REST API changes using versioned URLs, so functionality stays stable.

Check out our comparison of old and new functionality to get a feel for the contrast between the old and new APIs.

Libraries

  • 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

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