Request methods
Requests come in two flavors:GET and POST. GET requests can be sent directly; POST requests must declare the method explicitly:
Available endpoints
The endpoints a panel can call are a subset of the full MarginNote CLI surface. See theAPI reference for everything an add-on can use.
Besides /bridge/v1, the page can reach other paths served by the panel itself, including files inside the add-on package, images, and panel resize controls. These paths never reach MarginNote and are not subject to the allowlist. See Path system for the syntax.
Error handling
mn.api does not reject on failure. Instead it returns the error object as a normal response body, so try...catch cannot catch a failed request.
Here is an example error response:
error field, then interpret the rest according to the specific request:
Endpoints that do not return JSON
mn.api(path, opts) is equivalent to calling fetch on /bridge/v1 and parsing the response as JSON:
SyntaxError while parsing and you cannot get the raw content. Use fetch directly for these endpoints. Examples:
GET /guidereturns Markdown.GET /notes/{noteid}/renderreturns a long card image or a PDF.GET /documents/{bookmd5}/pages/{index}/content/{contentId}returns an image.GET /bundles/{bundleId}/fileswith apathreturns the raw bytes of that file.
/bridge/v1 and the other available paths, see Path system.