Help:Contributing/api: Difference between revisions

From Wikibase
Jump to navigation Jump to search
docs: migrate contribution guide §8 (API and bulk editing) from docs/contribution-guide.md (via create-page on MediaWiki MCP Server)
 
Standardize: add copy button to block code snippets
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<languages/>
The full Wikibase API is available at <code>https://wikibase.ronzz.org/api.php</code>. 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]].


<translate>
<!--T:1-->
The full Wikibase API is available at <tvar name="api"><syntaxhighlight lang="text" inline>https://wikibase.ronzz.org/api.php</syntaxhighlight></tvar>. It requires login and a CSRF token. This page is for editors who want to script or bulk-edit; for interactive editing, see <tvar name="entities">[[Help:Contributing/entities]]</tvar>.
</translate>
<translate>
<!--T:2-->
Log in and get a CSRF token (adjust the credentials):
Log in and get a CSRF token (adjust the credentials):
</translate>


<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 20:
</syntaxhighlight>
</syntaxhighlight>


<translate>
Key API actions: <code>wbeditentity</code> (create/update), <code>wbgetentities</code> (read), <code>wbcreateclaim</code>/<code>wbsetclaim</code> (statements), <code>wbsearchentities</code> (find by label), <code>wbremoveclaims</code>. A REST API is also available under <code>/w/rest.php/wikibase/</code>.
<!--T:3-->
Key API actions: <tvar name="a1"><syntaxhighlight lang="text" inline>wbeditentity</syntaxhighlight></tvar> (create/update), <tvar name="a2"><syntaxhighlight lang="text" inline>wbgetentities</syntaxhighlight></tvar> (read), <tvar name="a3"><syntaxhighlight lang="text" inline>wbcreateclaim</syntaxhighlight></tvar>/<tvar name="a4"><syntaxhighlight lang="text" inline>wbsetclaim</syntaxhighlight></tvar> (statements), <tvar name="a5"><syntaxhighlight lang="text" inline>wbsearchentities</syntaxhighlight></tvar> (find by label), <tvar name="a6"><syntaxhighlight lang="text" inline>wbremoveclaims</syntaxhighlight></tvar>. A REST API is also available under <tvar name="rest"><syntaxhighlight lang="text" inline>/w/rest.php/wikibase/</syntaxhighlight></tvar>.
</translate>


== <translate><!--T:4--> Bulk tools</translate> ==
== Bulk tools ==


<translate>
<!--T:5-->
These tools are not installed on the instance — run them from your own machine:
These tools are not installed on the instance — run them from your own machine:
* [https://github.com/LeMyst/WikibaseIntegrator WikibaseIntegrator] (Python)
* [https://github.com/LeMyst/WikibaseIntegrator WikibaseIntegrator] (Python)
* [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)
</translate>


== <translate><!--T:6--> See also</translate> ==
== See also ==


<translate>
* [[Help:Contributing]] — the hub
<!--T:7-->
* <tvar name="hub">[[Help:Contributing]]</tvar> — the hub
* [https://www.mediawiki.org/wiki/Wikibase Wikibase documentation] (official)
* [https://www.mediawiki.org/wiki/Wikibase Wikibase documentation] (official)
* [https://www.wikidata.org/w/api.php action=wb…] API reference (Wikidata)
* [https://www.wikidata.org/w/api.php action=wb…] API reference (Wikidata)
</translate>

Latest revision as of 09:46, 23 August 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:

See also