DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:jsonrpc

This is an old revision of the document!


JSON-RPC API

develonly

:!: note this is currently experimental. Feedback via Github issues is welcome. The interface might still change.

This API provides access to all remote API functionality described in XML-RPC using a more modern JSON based API.

Get It Working

  1. Set the remote option to enable JSON-RPC in the Configuration Settings “Authentication” section
  2. Set the remoteuser option with a mix of comma separated “usernames,@groups”
  3. For security reasons it's safer to allow access to the JSON-RPC over HTTPS only. DokuWiki's .htaccess.dist contains some rewrite rules to do that.
  4. If you want to access the API from JavaScript, you might want to tune the remotecors option

Accessing The JSON-RPC Interface

You can access the JSON-RPC interface via the following URL:

http(s)://<your wiki/domain/ip>/lib/exe/jsonrpc.php

The API allows access via two different protocols:

  1. A simplified RPC protocol, where the the method to call is passed as a path segment and the body contains the array of parameters to pass
  2. Standard conform JSON-RPC calls either using version 1.0, 1.1 or 2.0.

Please note: this is not a REST API. All calls have to made as POST requests.

Simplified Access

This is the easiest way to interact with the API when you're implementing it yourself.

The function you want to call has to be given as a path segment:

http(s)://<your wiki/domain/ip>/lib/exe/jsonrpc.php/<function>

All parameters are passed as a JSON Array in the body of the request. Here's an example using curl:

curl http://localhost/dokuwiki/lib/exe/jsonrpc.php/wiki.getPageInfo \
   -H 'Content-Type: application/json' \
   -H "Authorization: Bearer $token" \
   -d '["wiki:syntax"]'

JSON-RPC Standard

The main difference to the simplified form is that all info, including the method to call is passed as body:

curl http://localhost/dokuwiki/lib/exe/jsonrpc.php/wiki.getPageInfo \
   -H 'Content-Type: application/json' \
   -H "Authorization: Bearer $token" \
   -d '{"jsonrpc": "2.0", "id": "something", "method": "wiki.getPageInfo", "params": ["wiki:syntax"]}'

Please note, when using version 2.0, only positional parameters are supported. Batching multiple calls is not supported.

Results

Results are always returned as a JSON object.

Here's an example response for a wiki.getPageInfo call:

{
  "result": {
    "name": "wiki:syntax",
    "lastModified": 1698917236,
    "author": "admin",
    "version": 1698917236
  },
  "error": {
    "code": 0,
    "message": "success"
  }
}

The result object is the result of your call, the error object will have a non-zero code if something goes wrong.

Available Functions

Please refer to the description at XMLRPC.

devel/jsonrpc.1701271826.txt.gz · Last modified: 2023-11-29 16:30 by andi

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki