HTTP Service API
Last modified by superadmin on 2026/11/11 11:22
Content
Reference
The page AdvancedBookmarks.Code.Service exposes the script services over HTTP, for JavaScript. Call it with the get action and an operation parameter: it answers with the JSON result of the matching method, under the same HTTP status.
| Operation | Request | Parameters | Method called |
|---|---|---|---|
| isBookmarked | GET | page | isBookmarked |
| toggle | POST | page, form_token | toggle |
| getBookmarks | GET | user (optional) | getBookmarks |
| save | POST | user (optional), data, version, form_token | save |
| export | GET | user (optional) | exportBookmarks |
| import | POST | user (optional), data, mode, version, form_token | importBookmarks |
| exportWiki | GET | admin.exportWiki | |
| startWikiImport | POST, multipart/form-data | mode, file, form_token | admin.startWikiImport |
| wikiImportStatus | GET | admin.getWikiImportStatus |
An unknown operation returns the unknownOperation error with the 400 status, and the unavailable error with the 503 status when the Java part of the extension is not installed.
// Add the current page to the bookmarks of the current user, or remove it.
const service = XWiki.Model.resolve('AdvancedBookmarks.Code.Service', XWiki.EntityType.DOCUMENT);
const body = new FormData();
body.append('operation', 'toggle');
body.append('page', XWiki.Model.serialize(XWiki.currentDocument.documentReference));
body.append('form_token', document.documentElement.dataset.xwikiFormToken);
const response = await fetch(new XWiki.Document(service).getURL('get'), {method: 'POST', body});
console.log(await response.json());The console then shows:
{"status": 200, "bookmarked": true}