Wikibase/API: Difference between revisions
→API modules: add wbcheckconstraintparameters (T174552) |
fix typo: *calender -> calendar |
||
| (45 intermediate revisions by 21 users not shown) | |||
| Line 4: | Line 4: | ||
<translate> |
<translate> |
||
== What is the Wikibase API? == <!--T:21--> |
== What is the Wikibase API? == <!--T:21--> |
||
<!--T:25--> |
|||
Wikibase provides a general mechanism to store statements as structured data. |
|||
</translate> |
</translate> |
||
<translate><!--T:25--> Wikibase provides a general mechanism for storing statements as structured data.</translate> |
|||
<translate> |
|||
<translate><!--T:28--> The statements about items live on the server at [[d:|wikidata.org]].</translate> |
|||
<!--T:28--> |
|||
<translate><!--T:26--> See [[<tvar name=d>d:Wikidata:Glossary</tvar>|Wikidata:Glossary]] for more information on Wikibase and other concepts.</translate> |
|||
The statements about items live on the server at [https://www.wikidata.org wikidata.org ].</translate> |
|||
<translate> |
|||
<!--T:26--> |
|||
See [[<tvar|d>d:Wikidata:Glossary</>|Wikidata:Glossary]] for more information on Wikibase and other concepts.</translate> |
|||
[[File:Wikidata_statement.svg|thumb|none|500x500px|A statement]] |
[[File:Wikidata_statement.svg|thumb|none|500x500px|<translate><!--T:152--> A statement</translate>]] |
||
The Wikibase API allows querying, adding, removing and editing information on Wikidata or any other Wikibase instance. |
<translate><!--T:153--> The Wikibase API allows querying, adding, removing and editing information on Wikidata or any other Wikibase instance.</translate> |
||
<translate><!--T:22--> It is provided via a set of extensions to MediaWiki API modules. </translate> |
|||
<translate><!--T:23--> So, to use the Wikibase API, you should have a basic familiarity with the [[<tvar name=1>Special:MyLanguage/API:Action API</tvar>|MediaWiki Action API]]: actions, queries, etc., as well as with generic parameters such as <tvar name=2><code>curtimestamp</code></tvar> and <tvar name=3><code>requestid</code></tvar>.</translate> |
|||
<translate> |
<translate> |
||
== How to use the Wikibase api == <!--T:154--> |
|||
<!--T:22--> |
|||
It is provided by a set of extensions that implement MediaWiki API modules. </translate> |
|||
<translate> |
|||
<!--T:23--> |
|||
So to use the Wikibase API, you should have basic familiarity with the [[API:Main page|MediaWiki Action API]]: actions, queries, etc., and conversely, your experience with generic parameters such as <code>curtimestamp</code> and <code>requestid</code> applies to the Wikibase API. |
|||
</translate> |
</translate> |
||
<translate><!--T:155--> Send requests to the API through [[:en:Hypertext_Transfer_Protocol|HTTP]], the same as with the MediaWiki Action API.</translate> <translate><!--T:156--> See [[<tvar name=1>Special:MyLanguage/API:Tutorial#How_to_use_it</tvar>|API:Tutorial#How to use it]] for information about how to use the MediaWiki Action API.</translate> |
|||
<translate> |
|||
== How to use it == |
|||
=== Request Format === <!--T:157--> |
|||
Send requests to the API through [[:en:Hypertext_Transfer_Protocol|HTTP]], the same way with the MediaWiki Action API. See [[API:Tutorial#How_to_use_it|API:Tutorial#How to use it]] for information on how to use the MediaWiki Action API. |
|||
<!--T:158--> |
|||
=== Request format === |
|||
The endpoint for the API is https://wikidata.org/w/api.php. |
The endpoint for the API is <tvar name=1>https://wikidata.org/w/api.php</tvar>.</translate> |
||
In the query string, add the action parameter which tells the API which action to perform, |
<translate><!--T:171--> In the query string, add the action parameter, which tells the API which action to perform.</translate> <translate><!--T:172--> For example, <tvar name=1><code>action=wbgetentities</code></tvar> tells the API to get the data for Wikibase entities.</translate> <translate><!--T:173--> For meta and property submodules, use <tvar name=1><code>action=query&meta=''yourmodule''</code></tvar> and <tvar name=2><code>action=query&prop=''modulename''</code></tvar> respectively.</translate> |
||
<translate> |
<translate> |
||
<!--T:45--> |
<!--T:45--> |
||
Some parameters are nearly always available. Plural forms are used in those cases in which a parameter can take several values. The parameters are: |
|||
</translate> |
</translate> |
||
*{{ApiParam|id/ids|<translate><!--T:46--> Identifies a specific ''entity'' or ''entities'', |
*{{ApiParam|id/ids|2=<translate><!--T:46--> 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 character</translate>}} |
||
*{{ApiParam|site ∩ title/sites ∩ titles|<translate><!--T:47--> Identifies a single item or multiple items. |
*{{ApiParam|site ∩ title/sites ∩ titles|2=<translate><!--T:47--> 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.</translate>}} |
||
*{{ApiParam|language/languages|<translate><!--T:48--> The language |
*{{ApiParam|language/languages|2=<translate><!--T:48--> The language parameter filters labels and descriptions in get actions or identifies a specific language for a set of actions.</translate>}} |
||
*{{ApiParam|format|<translate><!--T:49--> Should always be set to ''json'' (or ''jsonfm for debugging''), or ''xml'' (or ''xmlfm for debugging'') |
*{{ApiParam|format|2=<translate><!--T:49--> Should always be set to ''json'' (or ''jsonfm for debugging''), or ''xml'' (or ''xmlfm for debugging''). No other form is supported.</translate>}} |
||
*{{ApiParam|summary|<translate><!--T:50--> Adds a user |
*{{ApiParam|summary|2=<translate><!--T:50--> Adds a user-specified summary in addition to the system-generated one.</translate>}} |
||
*{{ApiParam|token|<translate><!--T:51--> An encrypted string the requester must pass |
*{{ApiParam|token|2=<translate><!--T:51--> An encrypted string the requester must pass for the request to be fulfilled.</translate>}} |
||
*{{ApiParam|baserevid|<translate><!--T:52--> An id for the last known revision that must be passed |
*{{ApiParam|baserevid|2=<translate><!--T:52--> An id for the last known revision that must be passed so that the server can detect edit collisions.</translate>}} |
||
<translate> |
|||
== A simple query == |
|||
== A simple query == <!--T:159--> |
|||
=== GET request === |
|||
=== GET request === <!--T:160--> |
|||
</translate> |
|||
{{ApiEx |
{{ApiEx |
||
|desc=Get the item for page "Berlin" on English Wikipedia. |
|desc=<translate><!--T:161--> Get the item for page "Berlin" on English Wikipedia.</translate> |
||
|site=www.wikidata.org |
|site=www.wikidata.org |
||
|p1=action=wbgetentities |
|p1=action=wbgetentities |
||
| Line 60: | Line 57: | ||
}} |
}} |
||
<translate> |
|||
<!--T:162--> |
|||
Explanation of each part of the URL: |
Explanation of each part of the URL: |
||
</translate> |
|||
* <code><nowiki>http://www.wikidata.org/w/api.php</nowiki></code> is the main endpoint. |
* <translate><!--T:163--> <tvar name=1><code><nowiki>http://www.wikidata.org/w/api.php</nowiki></code></tvar> is the main endpoint.</translate> |
||
* <code>action=wbgetentities</code> tells the API to get the data for Wikibase entities. |
* <translate><!--T:164--> <tvar name=1><code>action=wbgetentities</code></tvar> tells the API to get the data for Wikibase entities.</translate> |
||
* <code>sites=enwiki</code> means get the data from English Wikipedia. |
* <translate><!--T:165--> <tvar name=1><code>sites=enwiki</code></tvar> means get the data from English Wikipedia.</translate> |
||
* <code>titles=Berlin</code> indicates the title of the page to get data from. |
* <translate><!--T:166--> <tvar name=1><code>titles=Berlin</code></tvar> indicates the title of the page to get data from.</translate> |
||
* <code>props=descriptions</code> indicates properties to get from the entities, in this case the property is the descriptions of the entities. |
* <translate><!--T:167--> <tvar name=1><code>props=descriptions</code></tvar> indicates properties to get from the entities, in this case the property is the descriptions of the entities.</translate> |
||
* <code>languages=en</code> means filter the results down to the English language. |
* <translate><!--T:168--> <tvar name=1><code>languages=en</code></tvar> means filter the results down to the English language.</translate> |
||
* <code>format=json</code> indicates JSON output, which is the recommended output format. |
* <translate><!--T:169--> <tvar name=1><code>format=json</code></tvar> indicates JSON output, which is the recommended output format.</translate> |
||
<translate> |
|||
=== Response === |
|||
=== Response === <!--T:170--> |
|||
</translate> |
|||
<syntaxhighlight lang="json"> |
<syntaxhighlight lang="json"> |
||
{ |
{ |
||
| Line 93: | Line 95: | ||
The response of a request will usually contain: |
The response of a request will usually contain: |
||
</translate> |
</translate> |
||
* <translate><!--T:141--> A <tvar|key1><code>success</code></> key with a boolean cast as an integer if the request is successful. If the integer is zero, any additional values might be wrong.</translate> |
|||
* <translate><!--T: |
* <translate><!--T:141--> A <tvar name=key1><code>success</code></tvar> key with a boolean cast as an integer if the request is successful. If the integer is zero, any additional values might be wrong.</translate> |
||
* <translate><!--T:142--> An <tvar name=key2><code>error</code></tvar> key with an object of two, optionally three keys, <tvar name=key4><code>code</code></tvar>, <tvar name=key5><code>info</code></tvar> and <tvar name=key6><code>*</code></tvar>, if the request is unsuccessful.</translate> |
|||
* <translate><!--T:143--> 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.</translate> |
* <translate><!--T:143--> 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.</translate> |
||
| Line 103: | Line 106: | ||
== API documentation and Wikibase modules == <!--T:36--> |
== API documentation and Wikibase modules == <!--T:36--> |
||
</translate> |
</translate> |
||
{{Note|1=Source-generated documentation for the MediaWiki Action API including Wikibase 'wb' API modules is available at [https://www.wikidata.org/w/api.php wikidata.org/w/api.php] }} |
{{Note|1=<translate><!--T:174--> Source-generated documentation for the MediaWiki Action API including Wikibase 'wb' API modules is available at <tvar name=1>[https://www.wikidata.org/w/api.php wikidata.org/w/api.php]</tvar></translate> }} |
||
<translate> |
|||
=== Meta submodules === |
|||
=== Meta submodules === <!--T:175--> |
|||
* [https://www.wikidata.org/w/api.php?action=help&recursivesubmodules=1#query+wikibase wikibase]: Gets information about the Wikibase client and the associated Wikibase repository. |
|||
</translate> |
|||
* [https://www.wikidata.org/w/api.php?action=help&recursivesubmodules=1#query+wbcontentlanguages wbcontentlanguages]: Returns information about the content languages Wikibase accepts in different contexts. |
|||
* [[d:Special:ApiHelp/query+wikibase|wikibase]]: {{Int|Apihelp-query+wikibase-description}} |
|||
=== Property submodules === |
|||
* [[d:Special:ApiHelp/query+wbcontentlanguages|wbcontentlanguages]]: {{Int|Apihelp-query+wbcontentlanguages-summary}} |
|||
<translate> |
|||
=== Property submodules === <!--T:176--> |
|||
</translate> |
|||
{{anchor|wbentityusage}}<!--Link from API help--> |
{{anchor|wbentityusage}}<!--Link from API help--> |
||
* [[d:Special:ApiHelp/query+pageterms|pageterms]]: {{Int|Apihelp-query+pageterms-description}} |
|||
* [https://www.wikidata.org/w/api.php?action=help&recursivesubmodules=1#query+pageterms pageterms]: Get the Wikidata terms (typically labels, descriptions and aliases) associated with a page via a sitelink. |
|||
* [ |
* [[d:Special:ApiHelp/query+wbentityusage|wbentityusage]]: {{Int|Apihelp-query+wbentityusage-description}} |
||
<translate> |
|||
=== API modules === |
|||
=== API modules === <!--T:177--> |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbgetentities wbgetentities]: Gets the data for multiple Wikibase entities. |
|||
</translate> |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbavailablebadges wbavailablebadges]: Queries available badge items. |
|||
* [[d:Special:ApiHelp/wbgetentities|wbgetentities]]: {{Int|Apihelp-wbgetentities-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbcreateclaim wbcreateclaim]: Creates Wikibase claims. |
|||
* [[d:Special:ApiHelp/wbavailablebadges|wbavailablebadges]]: {{Int|Apihelp-wbavailablebadges-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbcreateredirect wbcreateredirect]: Creates Entity redirects. |
|||
* [[d:Special:ApiHelp/wbcreateclaim|wbcreateclaim]]: {{Int|Apihelp-wbcreateclaim-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbeditentity wbeditentity]: Creates a single new Wikibase entity and modifies it with serialised information. |
|||
* [[d:Special:ApiHelp/wbcreateredirect|wbcreateredirect]]: {{Int|Apihelp-wbcreateredirect-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbformatvalue wbformatvalue]: Formats DataValues. |
|||
* [[d:Special:ApiHelp/wbeditentity|wbeditentity]]: {{Int|Apihelp-wbeditentity-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbgetclaims wbgetclaims]: Gets Wikibase claims. |
|||
* [[d:Special:ApiHelp/wbformatvalue|wbformatvalue]]: {{Int|Apihelp-wbformatvalue-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wblinktitles wblinktitles]: Associates two pages on two different wikis with a Wikibase item. |
|||
* [[d:Special:ApiHelp/wbgetclaims|wbgetclaims]]: {{Int|Apihelp-wbgetclaims-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbmergeitems wbmergeitems]: Merges multiple items. |
|||
* [[d:Special:ApiHelp/wblinktitles|wblinktitles]]: {{Int|Apihelp-wblinktitles-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbparsevalue wbparsevalue]: Parses values using a ValueParser. |
|||
* [[d:Special:ApiHelp/wbmergeitems|wbmergeitems]]: {{Int|Apihelp-wbmergeitems-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbremoveclaims wbremoveclaims]: Removes Wikibase claims. |
|||
* [[d:Special:ApiHelp/wbparsevalue|wbparsevalue]]: {{Int|Apihelp-wbparsevalue-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbremovequalifiers wbremovequalifiers]: Removes a qualifier from a claim. |
|||
* [[d:Special:ApiHelp/wbremoveclaims|wbremoveclaims]]: {{Int|Apihelp-wbremoveclaims-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbremovereferences wbremovereferences]: Removes one or more references of the same statement. |
|||
* [[d:Special:ApiHelp/wbremovequalifiers|wbremovequalifiers]]: {{Int|Apihelp-wbremovequalifiers-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsearchentities wbsearchentities]: Searches for entities using labels and aliases. |
|||
* [[d:Special:ApiHelp/wbremovereferences|wbremovereferences]]: {{Int|Apihelp-wbremovereferences-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetaliases wbsetaliases]: Sets the aliases for a Wikibase entity. |
|||
* [[d:Special:ApiHelp/wbsearchentities|wbsearchentities]]: {{Int|Apihelp-wbsearchentities-summary}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetclaim wbsetclaim]: Creates or updates an entire Statement or Claim. |
|||
* [[d:Special:ApiHelp/wbsetaliases|wbsetaliases]]: {{Int|Apihelp-wbsetaliases-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetclaimvalue wbsetclaimvalue]: Sets the value of a Wikibase claim. |
|||
* [[d:Special:ApiHelp/wbsetclaim|wbsetclaim]]: {{Int|Apihelp-wbsetclaim-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetdescription wbsetdescription]: Sets a description for a single Wikibase entity. |
|||
* [[d:Special:ApiHelp/wbsetclaimvalue|wbsetclaimvalue]]: {{Int|Apihelp-wbsetclaimvalue-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetlabel wbsetlabel]: Sets a label for a single Wikibase entity. |
|||
* [[d:Special:ApiHelp/wbsetdescription|wbsetdescription]]: {{Int|Apihelp-wbsetdescription-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetqualifier wbsetqualifier]: Creates a qualifier or sets the value of an existing one. |
|||
* [[d:Special:ApiHelp/wbsetlabel|wbsetlabel]]: {{Int|Apihelp-wbsetlabel-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetreference wbsetreference]: Creates a reference or sets the value of an existing one. |
|||
* [[d:Special:ApiHelp/wbsetqualifier|wbsetqualifier]]: {{Int|Apihelp-wbsetqualifier-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsetsitelink wbsetsitelink]: Associates a page on a wiki with a Wikibase item or removes an already made such association. |
|||
* [[d:Special:ApiHelp/wbsetreference|wbsetreference]]: {{Int|Apihelp-wbsetreference-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbsgetsuggestions wbsgetsuggestions]: Gets suggestions of additional properties to add to a Wikibase entity. |
|||
* [[d:Special:ApiHelp/wbsetsitelink|wbsetsitelink]]: {{Int|Apihelp-wbsetsitelink-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbcheckconstraints wbcheckconstraints]: Performs constraint checks on any entity you want and returns the result. |
|||
* [[d:Special:ApiHelp/wbsgetsuggestions|wbsgetsuggestions]]: {{Int|Apihelp-wbsgetsuggestions-description}} |
|||
* [https://wikidata.org/w/api.php?action=help&modules=wbcheckconstraintparameters wbcheckconstraintparameters]: Checks the constraint parameters of constraint statements. |
|||
* [[d:Special:ApiHelp/wbcheckconstraints|wbcheckconstraints]]: {{Int|Apihelp-wbcheckconstraints-description}} |
|||
* [[d:Special:ApiHelp/wbcheckconstraintparameters|wbcheckconstraintparameters]]: {{Int|Apihelp-wbcheckconstraintparameters-summary}} |
|||
<translate> |
<translate> |
||
==Possible errors== <!--T:125--> |
==Possible errors== <!--T:125--> |
||
<!--T:126--> |
|||
Possible errors for any module can be found using <tvar|1><code>action=paraminfo&modules=''modulename''</code></>. |
|||
</translate> |
</translate> |
||
<translate><!--T:126--> Possible errors for any module can be found using <tvar name=1><code>action=paraminfo&modules=''modulename''</code></tvar>.</translate> |
|||
The error format corresponds to that of the Mediawiki Action API. See [[API:Errors_and_warnings#Legacy_format|API:Errors and warnings#Legacy format]]. |
|||
<translate><!--T:178--> The error format corresponds to that of the MediaWiki Action API.</translate> <translate><!--T:179--> See [[<tvar name=1>Special:MyLanguage/API:Errors_and_warnings#Legacy_format</tvar>|API:Errors and warnings#Legacy format]].</translate> |
|||
<translate><!--T:130--> All error messages from the Wikibase modules should be internationalised ([[w:I18n|i18n]]) and localised ([[w:L10n|l10n]]). The user language for the logged-in user will be the default for error messages, but you can override this by adding <tvar name=lc><code>uselang=''languageCode''</code></tvar> to the URL query string.</translate> |
|||
<translate> |
|||
<!--T:130--> |
|||
All error messages from the Wikibase modules should be internationalized ([[w:en:I18n|i18n]]) and localized ([[w:en:L10n|l10n]]). The user language for the logged-in user will be the default for error messages, but you can override this by adding <tvar|lc><code>uselang=''languageCode''</code></> to the URL query string. |
|||
</translate> |
|||
{| class="wikitable" |
{| class="wikitable" |
||
|+ |
|+ |
||
!Error type |
!<translate><!--T:149--> Error type</translate> |
||
!<translate><!--T:150--> Code</translate> |
|||
!Code |
|||
!<translate><!--T:151--> Info</translate> |
|||
!Info |
|||
|- |
|- |
||
|An internationalized error message that isn't localized. |
|An internationalized error message that isn't localized. |
||
| Line 173: | Line 177: | ||
|} |
|} |
||
== Additional notes == |
|||
<translate> |
<translate> |
||
== Additional notes == <!--T:180--> |
|||
<!--T:57--> |
<!--T:57--> |
||
* Many Wikimedia wikis run the [[<tvar |
* Many Wikimedia wikis run the [[<tvar name=ext>Extension:Wikibase Client</tvar>|Wikibase Client extension]]. This lets API clients on them to query the <tvar name=wb><code>wikibase</code></tvar> meta submodule to determine URLs for the full Wikibase repo, and the <tvar name=prop><code>pageterms</code></tvar> property submodule to get some Wikidata information about pages on the local wiki.</translate> |
||
</translate> |
|||
<translate> |
<translate> |
||
<!--T:120--> |
<!--T:120--> |
||
* The |
* The calendar models that can be used with Wikibase are the Gregorian calendar(<tvar name=d1>[[d:Q1985727]]</tvar>) and the Julian calendar(<tvar name=d2>[[d:Q1985786]]</tvar>).</translate> |
||
</translate> |
|||
<translate> |
<translate> |
||
<!--T:124--> |
<!--T:124--> |
||
| Line 187: | Line 190: | ||
<translate> |
<translate> |
||
<!--T:27--> |
<!--T:27--> |
||
* Any MediaWiki installation can run Wikibase. On the Wikimedia cluster, most wikis do not run the full set of Wikibase extensions.</translate> <translate><!--T:30--> |
* Any MediaWiki installation can run Wikibase. On the Wikimedia cluster, most wikis do not run the full set of Wikibase extensions.</translate> <translate><!--T:30--> Wikimedia Commons has its own Wikibase for properties of the files on Commons.</translate> |
||
<translate> |
|||
* Do not test the <code>info</code> value for a particular error, instead use the <code>code</code> value as this will remain independent of localization. |
|||
<!--T:148--> |
|||
* Do not test the <tvar name=1><code>info</code></tvar> value for a particular error, instead use the <tvar name=2><code>code</code></tvar> value as this will remain independent of localisation. |
|||
<translate> |
|||
==See also== <!--T:2--> |
==See also== <!--T:2--> |
||
</translate> |
</translate> |
||
* {{ll|API: |
* {{ll|API:Action API}} - <translate><!--T:144--> The quick start guide for the MediaWiki Action API.</translate> |
||
* {{ll|API:FAQ}} - <translate><!--T:145--> Frequently asked questions about the MediaWiki Action API.</translate> |
* {{ll|API:FAQ}} - <translate><!--T:145--> Frequently asked questions about the MediaWiki Action API.</translate> |
||
* {{ll|API:Tutorial}} - <translate><!--T:146--> A tutorial on how to use the MediaWiki Action API.</translate> |
* {{ll|API:Tutorial}} - <translate><!--T:146--> A tutorial on how to use the MediaWiki Action API.</translate> |
||
Latest revision as of 11:32, 31 January 2026
This page is part of the MediaWiki Action API documentation. |
| MediaWiki version: | ≥ 1.9 |
What is the Wikibase API?
[edit | edit source]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.

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.
How to use the Wikibase api
[edit | edit source]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.
Request Format
[edit | edit source]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.
A simple query
[edit | edit source]GET request
[edit | edit source]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
[edit | edit source]{
"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
[edit | edit source]Meta submodules
[edit | edit source]- wikibase: ⧼Apihelp-query+wikibase-description⧽
- wbcontentlanguages: Returns information about the content languages Wikibase accepts in different contexts.
Property submodules
[edit | edit source]
- pageterms: ⧼Apihelp-query+pageterms-description⧽
- wbentityusage: ⧼Apihelp-query+wbentityusage-description⧽
API modules
[edit | edit source]- wbgetentities: ⧼Apihelp-wbgetentities-description⧽
- wbavailablebadges: ⧼Apihelp-wbavailablebadges-description⧽
- wbcreateclaim: ⧼Apihelp-wbcreateclaim-description⧽
- wbcreateredirect: ⧼Apihelp-wbcreateredirect-description⧽
- wbeditentity: ⧼Apihelp-wbeditentity-description⧽
- wbformatvalue: ⧼Apihelp-wbformatvalue-description⧽
- wbgetclaims: ⧼Apihelp-wbgetclaims-description⧽
- wblinktitles: ⧼Apihelp-wblinktitles-description⧽
- wbmergeitems: ⧼Apihelp-wbmergeitems-description⧽
- wbparsevalue: ⧼Apihelp-wbparsevalue-description⧽
- wbremoveclaims: ⧼Apihelp-wbremoveclaims-description⧽
- wbremovequalifiers: ⧼Apihelp-wbremovequalifiers-description⧽
- wbremovereferences: ⧼Apihelp-wbremovereferences-description⧽
- wbsearchentities: Searches for entities using labels and aliases.
- wbsetaliases: ⧼Apihelp-wbsetaliases-description⧽
- wbsetclaim: ⧼Apihelp-wbsetclaim-description⧽
- wbsetclaimvalue: ⧼Apihelp-wbsetclaimvalue-description⧽
- wbsetdescription: ⧼Apihelp-wbsetdescription-description⧽
- wbsetlabel: ⧼Apihelp-wbsetlabel-description⧽
- wbsetqualifier: ⧼Apihelp-wbsetqualifier-description⧽
- wbsetreference: ⧼Apihelp-wbsetreference-description⧽
- wbsetsitelink: ⧼Apihelp-wbsetsitelink-description⧽
- wbsgetsuggestions: ⧼Apihelp-wbsgetsuggestions-description⧽
- wbcheckconstraints: ⧼Apihelp-wbcheckconstraints-description⧽
- wbcheckconstraintparameters: Checks the constraint parameters of constraint statements.
Possible errors
[edit | edit source]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 | <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
[edit | edit source]- 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 calendar 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 localisation.
See also
[edit | edit source]- API:Action API - 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.