Open main menu
This page is a translated version of the page Wikibase/API and the translation is 41% complete.

Outdated translations are marked like this.

Qu'est-ce que l'api Wikibase ?

Wikibase fournit un mécanisme général pour ranger des déclarations en tant que données structurées. Les déclarations concernant les éléments se trouvent sur le serveur wikidata.org . Voir wikidata:Glossary pour plus d'explications sur Wikibase et d'autres concepts.

 
A statement

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

L'API Wikibase est représentée par un ensemble d'extensions qui implémentent les modules de l'API MediaWiki.

Ainsi pour l'utiliser vous vous devriez avoir une connaissance de base de l'API web MediaWiki: actions, requêtes, etc., et inversement toute votre expérience avec les paramètres génériques comme curtimestamp et requestid, etc. s'appliquera à l'API Wikibase.

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.

Certains paramètres sont presque toujours disponibles. Les formes plurielles sont utilisées dans les cas où un paramètre peut prendre plusieurs valeurs.

  • id/ids
  • site ∩ title/sites ∩ titles: identifie un seul élément ou plusieurs éléments. La forme plurielle est utilisée dans wb getentities . Un seul des sites et titres peut avoir plusieurs valeurs en même temps.
  • language/languages: La langue est utilisée comme mécanisme de filtrage pour filtrer les étiquettes et les descriptions dans les actions get ou pour identifier une langue spécifique pour les actions définies.
  • 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

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

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

La réponse à la requête contient généralement :

  • 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.

Documentation de l'API et modules de Wikibase

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

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

Erreurs possibles

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 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 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 wbgetentities for the item in question, and then storing (and using) the revision from the entry.

Sur le cluster Wikimedia, la plupart des wikis n'utilisent pas l'ensemble complet des extensions Wikibase.

(Wikimedia Commons possède sa propre Wikibase pour les propriétés des fichiers sur Commons).

  • Do not test the info value for a particular error, instead use the code value as this will remain independent of localization.

Voir aussi