Wikibase/API (original) (raw)

Languages:

Wikibase provides a general mechanism for storing statements as structured data. The statements about items live on the server at wikidata.org. See Wikidata:Glossary for more information on Wikibase and other concepts.

A statement

The Wikibase API allows querying, adding, removing and editing information on Wikidata or any other Wikibase instance.

It is provided via a set of extensions to MediaWiki API modules. So, to use the Wikibase API, you should have a basic familiarity with the MediaWiki Action API: actions, queries, etc., as well as with generic parameters such as curtimestamp and requestid.

Send requests to the API through HTTP, the same as with the MediaWiki Action API. See API:Tutorial#How to use it for information about how to use the MediaWiki Action API.

The endpoint for the API is https://wikidata.org/w/api.php.

In the query string, add the action parameter, which tells the API which action to perform. For example, action=wbgetentities tells the API to get the data for Wikibase entities. For meta and property submodules, use action=query&meta=_yourmodule_ and action=query&prop=_modulename_ respectively.

Some parameters are nearly always available. Plural forms are used in those cases in which a parameter can take several values. The parameters are:

Get the item for page "Berlin" on English Wikipedia.

Explanation of each part of the URL:

{ "entities": { "Q64": { "type": "item", "id": "Q64", "descriptions": { "en": { "language": "en", "value": "capital and largest city of Germany" } } } }, "success": 1 }

The response of a request will usually contain:

Empty objects are returned as JSON arrays and not as objects, while empty parameters remove the actual entry from the item.

Source-generated documentation for the MediaWiki Action API including Wikibase 'wb' API modules is available at wikidata.org/w/api.php

Property submodules

[edit]

Possible errors for any module can be found using action=paraminfo&modules=_modulename_. The error format corresponds to that of the MediaWiki Action API. See API:Errors and warnings#Legacy format.

All error messages from the Wikibase modules should be internationalised (i18n) and localised (l10n). The user language for the logged-in user will be the default for error messages, but you can override this by adding uselang=_languageCode_ to the URL query string.

Error type Code Info
An internationalized error message that isn't localized. no-such-item
A correctly localized error message. no-such-item There are no such item to be found
A localized variant.(Norwegian) no-such-item Det finnes ingen slik item