Wikibase/API
This page is part of the MediaWiki Action API documentation. |
| MediaWiki version: | ≥ 1.9 |
What is the Wikibase API?
Wikibase provides a general mechanism to store 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.

The Wikibase API allows querying, adding, removing and editing information on Wikidata or any other Wikibase instance.
It is provided by a set of extensions that implement MediaWiki API modules.
So to use the Wikibase API, you should have basic familiarity with the MediaWiki Action API: actions, queries, etc., and conversely, your experience with generic parameters such as curtimestamp and requestid applies to the Wikibase API.
How to use it
Send requests to the API through HTTP, the same way with the MediaWiki Action API. See API:Tutorial#How to use it for information on how to use the MediaWiki Action API.
Request format
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, e.g. action=wbgetentities tells the API to get the data for Wikibase entities. For meta and property submodules, use action=query&meta=yourmoduleand action=query&prop=modulename respectively.
There are some parameters that are nearly always available. Plural forms are used in those cases where a parameter can take several values. The parameters are:
id/ids: Identifies a specific entity or entities, most typical an item. 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. Plural form is used in wbgetentities. Only one of sites and titles can have multiple values at the same time.language/languages: The language is used as a filter mechanism to filter labels and descriptions in get actions or to identify a specific language for set 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 on shall the request be fulfilled.baserevid: An id for the last known revision that must be passed on so the server can detect edit collisions.
A simple query
GET request
Explanation of each part of the URL:
http://www.wikidata.org/w/api.phpis the main endpoint.action=wbgetentitiestells the API to get the data for Wikibase entities.sites=enwikimeans get the data from English Wikipedia.titles=Berlinindicates the title of the page to get data from.props=descriptionsindicates properties to get from the entities, in this case the property is the descriptions of the entities.languages=enmeans filter the results down to the English language.format=jsonindicates JSON output, which is the recommended output format.
Response
{
"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:
- A
successkey with a boolean cast as an integer if the request is successful. If the integer is zero, any additional values might be wrong. - An
errorkey with an object of two, optionally three keys,code,infoand*, if the request is unsuccessful. - Information about the action. The information is either passed on the top level or under item if it is one single item or items if it is several. If it is several items, each is found under a key with its own item id.
Empty objects are returned as JSON arrays and not as objects, while empty parameters remove the actual entry from the item.
API documentation and Wikibase modules
Meta submodules
- wikibase: Gets information about the Wikibase client and the associated Wikibase repository.
- wbcontentlanguages: Returns information about the content languages Wikibase accepts in different contexts.
Property submodules
- pageterms: Get the Wikidata terms (typically labels, descriptions and aliases) associated with a page via a sitelink.
- wbentityusage: Returns all entity IDs used in the given pages.
API modules
- wbgetentities: Gets the data for multiple Wikibase entities.
- wbavailablebadges: Queries available badge items.
- wbcreateclaim: Creates Wikibase claims.
- wbcreateredirect: Creates Entity redirects.
- wbeditentity: Creates a single new Wikibase entity and modifies it with serialised information.
- wbformatvalue: Formats DataValues.
- wbgetclaims: Gets Wikibase claims.
- wblinktitles: Associates two pages on two different wikis with a Wikibase item.
- wbmergeitems: Merges multiple items.
- wbparsevalue: Parses values using a ValueParser.
- wbremoveclaims: Removes Wikibase claims.
- wbremovequalifiers: Removes a qualifier from a claim.
- wbremovereferences: Removes one or more references of the same statement.
- wbsearchentities: Searches for entities using labels and aliases.
- wbsetaliases: Sets the aliases for a Wikibase entity.
- wbsetclaim: Creates or updates an entire Statement or Claim.
- wbsetclaimvalue: Sets the value of a Wikibase claim.
- wbsetdescription: Sets a description for a single Wikibase entity.
- wbsetlabel: Sets a label for a single Wikibase entity.
- wbsetqualifier: Creates a qualifier or sets the value of an existing one.
- wbsetreference: Creates a reference or sets the value of an existing one.
- wbsetsitelink: Associates a page on a wiki with a Wikibase item or removes an already made such association.
- wbsgetsuggestions: Gets suggestions of additional properties to add to a Wikibase entity.
- wbcheckconstraints: Performs constraint checks on any entity you want and returns the result.
- wbcheckconstraintparameters: Checks the constraint parameters of constraint statements.
Possible errors
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 internationalized (i18n) and localized (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 | <wikibase-api-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 |
Additional notes
- Many Wikimedia wikis run the Wikibase Client extension. This lets API clients on them to query the
wikibasemeta submodule to determine URLs for the full Wikibase repo, and thepagetermsproperty submodule to get some Wikidata information about pages on the local wiki. - The calender models that can be used with Wikibase are the Gregorian calendar(d:Q1985727) and the Julian calendar(d:Q1985786).
- The API uses revision ids for edit collision detection. If there is an edit collision, the requester must acquire a newer revision id to be able to continue. This typically involves requesting
wbgetentitiesfor the item in question, and then storing (and using) the revision from the entry. - Any MediaWiki installation can run Wikibase. On the Wikimedia cluster, most wikis do not run the full set of Wikibase extensions. Wikimedia Commons has its own Wikibase for properties of the files on Commons.
- Do not test the
infovalue for a particular error, instead use thecodevalue as this will remain independent of localization.
See also
- API:Main page - The quick start guide for the MediaWiki Action API.
- API:FAQ - Frequently asked questions about the MediaWiki Action API.
- API:Tutorial - A tutorial on how to use the MediaWiki Action API.
- Download Wikidata database dumps in JSON (recommended), XML and RDF formats.