Jump to content

Help:Contributing/api: Difference between revisions

From Wikibase
Rewrite in code-guide style: strip translation markup, <code> for plain tokens (via update-page on MediaWiki MCP Server)
docs: note the Add*/Update* form URL query-param prefill (the GUI as a "web API") (via update-page on MediaWiki MCP Server)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
Log in and get a CSRF token (adjust the credentials):
Log in and get a CSRF token (adjust the credentials):


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash" copy>
# 1) Log in
# 1) Log in
curl -s -c /tmp/wb.cookies "https://wikibase.ronzz.org/api.php" \
curl -s -c /tmp/wb.cookies "https://wikibase.ronzz.org/api.php" \
Line 28: Line 28:
* [https://www.mediawiki.org/wiki/Manual:Pywikibot Pywikibot] (official manual)
* [https://www.mediawiki.org/wiki/Manual:Pywikibot Pywikibot] (official manual)
* [https://www.wikidata.org/wiki/Help:QuickStatements QuickStatements] (spreadsheet-style batch)
* [https://www.wikidata.org/wiki/Help:QuickStatements QuickStatements] (spreadsheet-style batch)
== 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:
<syntaxhighlight lang="text" copy>
https://wikibase.ronzz.org/wiki/Special:AddSource/law/manual?parent=Q2048&referenceCode=Article%209
</syntaxhighlight>
Any field whose name appears in the query string opens with that value filled in (here the parent legislation <code>Q2048</code> 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 (<code>title</code>, <code>action</code>, <code>oldid</code>, …) are never treated as field values. This is the browser-form counterpart to the write modules <code>action=addsource</code> / <code>action=addspecialcontent</code> / <code>action=addsemanticentity</code> — see [[Help:Contributing/import]].


== See also ==
== See also ==

Latest revision as of 09:12, 10 October 2026

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