Jump to content

Wikibase/API: Difference between revisions

From mediawiki.org
Content deleted Content added
m Reverted edits by 2601:C5:C001:2430:60FE:719D:EEBB:362F (talk) to last version by Shirayuki
fix typo: *calender -> calendar
 
(32 intermediate revisions by 15 users not shown)
Line 6: Line 6:
</translate>
</translate>
<translate><!--T:25--> Wikibase provides a general mechanism for storing statements as structured data.</translate>
<translate><!--T:25--> Wikibase provides a general mechanism for storing statements as structured data.</translate>
<translate><!--T:28--> The statements about items live on the server at [https://www.wikidata.org wikidata.org ].</translate>
<translate><!--T:28--> The statements about items live on the server at [[d:|wikidata.org]].</translate>
<translate><!--T:26--> See [[<tvar|d>d:Wikidata:Glossary</>|Wikidata:Glossary]] for more information on Wikibase and other concepts.</translate>
<translate><!--T:26--> See [[<tvar name=d>d:Wikidata:Glossary</tvar>|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: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 [[API:Main page|MediaWiki Action API]]: actions, queries, etc., as well as with generic parameters such as <code>curtimestamp</code> and <code>requestid</code>.</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>
== How to use the Wikibase api ==
== How to use the Wikibase api == <!--T:154-->
Send requests to the API through [[:en:Hypertext_Transfer_Protocol|HTTP]], the same as with the MediaWiki Action API. See [[API:Tutorial#How_to_use_it|API:Tutorial#How to use it]] for information about how to use the MediaWiki Action API.
</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>
=== Request Format === <!--T:157-->


<!--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. For example, <code>action=wbgetentities</code> tells the API to get the data for Wikibase entities. For meta and property submodules, use <code>action=query&meta=''yourmodule''</code>and <code>action=query&prop=''modulename''</code> respectively.
<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>
Line 36: Line 41:
*{{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>}}
*{{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 49: 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 83: Line 96:
</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: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|key2><code>error</code></> key with an object of two, optionally three keys, <tvar|key4><code>code</code></>, <tvar|key5><code>info</code></> and <tvar|key6><code>*</code></>, if the request is unsuccessful.</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 93: 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.
* [https://www.wikidata.org/w/api.php?action=help&recursivesubmodules=1#query+wbentityusage wbentityusage]: Returns all entity IDs used in the given pages.
* [[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 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>
<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>


{| 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 159: Line 177:
|}
|}


== Additional notes ==
<translate>
<translate>
== Additional notes == <!--T:180-->

<!--T:57-->
<!--T:57-->
* Many Wikimedia wikis run the [[<tvar|ext>Extension:Wikibase Client</>|Wikibase Client extension]]. This lets API clients on them to query the <tvar|wb><code>wikibase</code></> meta submodule to determine URLs for the full Wikibase repo, and the <tvar|prop><code>pageterms</code></> property submodule to get some Wikidata information about pages on the local wiki.</translate>
* 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>
<!--T:120-->
<!--T:120-->
* The calender models that can be used with Wikibase are the Gregorian calendar(<tvar|d1>[[d:Q1985727]]</>) and the Julian calendar(<tvar|d2>[[d:Q1985786]]</>).</translate>
* 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>
<!--T:124-->
<!--T:124-->
Line 174: Line 193:
<translate>
<translate>
<!--T:148-->
<!--T:148-->
* Do not test the <tvar|1><code>info</code></> value for a particular error, instead use the <tvar|2><code>code</code></> value as this will remain independent of localization.
* 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.


==See also== <!--T:2-->
==See also== <!--T:2-->
</translate>
</translate>
* {{ll|API:Main page}} - <translate><!--T:144--> The quick start guide for the MediaWiki Action API.</translate>
* {{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

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.

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.

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 character
  • site ∩ 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]
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.

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 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.
  • An error key with an object of two, optionally three keys, code, info and *, 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]
Source-generated documentation for the MediaWiki Action API including Wikibase 'wb' API modules is available at wikidata.org/w/api.php

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]

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 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.
  • 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 wbgetentities for 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 info value for a particular error, instead use the code value as this will remain independent of localisation.

See also

[edit | edit source]