Jump to content

Help:Contributing/api

From Wikibase

Languages: English · français · Esperanto

The full Wikibase API is available at https://wikibase.ronzz.org/api.php. It requires login and a CSRF token. This page is for editors who want to script or bulk-edit; for interactive editing, see Help:Contributing/entities.

Log in and get a CSRF token (adjust the credentials):

# 1) Log in
curl -s -c /tmp/wb.cookies "https://wikibase.ronzz.org/api.php" \
  --data-urlencode "action=query" --data-urlencode "meta=tokens" \
  --data-urlencode "type=login" --data-urlencode "format=json"
# …POST action=login with lgname/lgpassword/lgtoken, then:
TOKEN=$(curl -s -b /tmp/wb.cookies "https://wikibase.ronzz.org/api.php?action=query&meta=tokens&format=json" \
  | python3 -c "import json,sys; print(json.load(sys.stdin)['query']['tokens']['csrftoken'])")

# 2) Create an item (wbeditentity)
curl -s -b /tmp/wb.cookies "https://wikibase.ronzz.org/api.php" \
  --data-urlencode "action=wbeditentity" --data-urlencode "new=item" \
  --data-urlencode "token=$TOKEN" \
  --data-urlencode 'data={"labels":{"en":{"language":"en","value":"My first item"}}}' \
  --data-urlencode "format=json"

Key API actions: wbeditentity (create/update), wbgetentities (read), wbcreateclaim/wbsetclaim (statements), wbsearchentities (find by label), wbremoveclaims. A REST API is also available under /w/rest.php/wikibase/.

Bulk tools

These tools are not installed on the instance — run them from your own machine:

Pre-filling an Add form from a URL

The Add\* / Update\* browser forms (and their manual steps) also read their field values from the URL query string, so the GUI is reachable as a lightweight "web API" — no session, CSRF token or item search needed just to open a form pre-filled:

https://wikibase.ronzz.org/wiki/Special:AddSource/law/manual?parent=Q2048&referenceCode=Article%209

Any field whose name appears in the query string opens with that value filled in (here the parent legislation Q2048 and the reference code). It is display-only convenience: a normal submit still requires login and re-validates every value, and MediaWiki's own routing parameters (title, action, oldid, …) are never treated as field values. This is the browser-form counterpart to the write modules action=addsource / action=addspecialcontent / action=addsemanticentity — see Help:Contributing/import.

See also