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 statementThe 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:
id/ids
: Identifies a specific entity or entities, typically an item. The plural form is used in wbgetentities. Lists of ids should be separated by the pipe charactersite ∩ title/sites ∩ titles
: Identifies a single item or multiple items. The plural form is used in wbgetentities. Only one of sites and titles can have multiple values at the same time.language/languages
: The language parameter filters labels and descriptions in get actions or identifies a specific language for a set of actions.format
: Should always be set to json (or jsonfm for debugging), or xml (or xmlfm for debugging). No other form is supported.summary
: Adds a user-specified summary in addition to the system-generated one.token
: An encrypted string the requester must pass for the request to be fulfilled.baserevid
: An id for the last known revision that must be passed so that the server can detect edit collisions.Get the item for page "Berlin" on English Wikipedia.
Explanation of each part of the URL:
http://www.wikidata.org/w/api.php
is the main endpoint.action=wbgetentities
tells the API to get the data for Wikibase entities.sites=enwiki
means get the data from English Wikipedia.titles=Berlin
indicates the title of the page to get data from.props=descriptions
indicates properties to get from the entities, in this case the property is the descriptions of the entities.languages=en
means filter the results down to the English language.format=json
indicates JSON output, which is the recommended output format.{ "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:
success
key with a boolean cast as an integer if the request is successful. If the integer is zero, any additional values might be wrong.error
key with an object of two, optionally three keys, code
, info
and *
, if the request is unsuccessful.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.phpPossible 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.
wikibase
meta submodule to determine URLs for the full Wikibase repo, and the pageterms
property submodule to get some Wikidata information about pages on the local wiki.wbgetentities
for the item in question, and then storing (and using) the revision from the entry.info
value for a particular error, instead use the code
value as this will remain independent of localisation.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4