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.

OperationRequestParametersMethod called
isBookmarkedGETpageisBookmarked
togglePOSTpage, form_tokentoggle
getBookmarksGETuser (optional)getBookmarks
savePOSTuser (optional), data, version, form_tokensave
exportGETuser (optional)exportBookmarks
importPOSTuser (optional), data, mode, version, form_tokenimportBookmarks
exportWikiGET admin.exportWiki
startWikiImportPOST, multipart/form-datamode, file, form_tokenadmin.startWikiImport
wikiImportStatusGET 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}

Get Connected