What is jsAPI
jsAPI is a Javascript library containing a single function - jsAPI(). This function allows interaction between Javascript code and Wikidot's XML-RPC API.
Quickstart
- Set up your Wikidot site with a HTTPS connection.
- Insert Javascript code calling the function jsAPI() with a valid API key.
- Version 3.0 of the code uses a synchronous connection with the Wikidot API Server1.
Version 3.1 uses both an asynchronous connection and synchronous connection. When a callback function is passed, asynchronous mode is enabled. - This means the use of a callback function is no longer required. The returned data is passed through the first argument of the callback function as wel as being returned in the jsAPI call.
The function
The function jsAPI() is included in jsAPI.
You must include the Javascript file for jsAPI.
- Use https://jsapi.wikidot.com/latest to always get the latest version.
- Use https://jsapi.wikidot.com/local--code/js/4 for the current latest version (v3.1).
To do this, you must add the following line before executing the jsAPI function.
<script type="text/javascript" src="https://jsapi.wikidot.com/local--code/js/4"></script>
The jsAPI consists of several arguments:
jsAPI(method, parameters, api-key, callback(data) );
Parameter | Required | Description |
---|---|---|
method | yes, string | any Wikidot API method |
parameters | yes, a structure object (a.k.a struct) | A structure containing the data for requesting the API. e.g. {"site": "site-name", "page": "start"} |
api-key | yes | 32-character-long Wikidot API Key |
callback | no | When a callback function is defined, asynchronous mode is enabled. Once the request is complete, the callback function passing an array of data as the first argument will be called. If callback function is not defined, synchronous mode is enabled and the data will be returned by the function. |
Examples of application
Without using callback function:
/* Returning data to a variable */ var data; data = jsAPI("pages.select", {"site": "sitename"}, "qwertyuiopasdfghjklzxcvbnm123456");
Using a callback function:
/* Requesting in asynchronous mode and returning data through a callback function */ jsAPI("pages.select", {"site": "sitename"}, "qwertyuiopasdfghjklzxcvbnm123456", function(a){ data=a; });
Retrieving data with data in an associative array:
/* Returning data to a variable */ var data; //Define the variable data data = jsAPI("pages.get_one", {"site": "sitename", "page": "start"}, "qwertyuiopasdfghjklzxcvbnm123456"); document.write(data["html"]); //writing the data returned in an associative array
Demos
You can try the re-tag tool, for mass editing tags on a site. It's built entirely using Javascript and jsAPI.
Alternatively, you can try the API tester below:
please wait while it loads…
Getting an API Key
You can get your own API key from Wikidot at the developer's wiki. Just reply the request thread.