Skip to main content
An add-on panel can talk to MarginNote to read information, modify it, and trigger actions.

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 the API 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:
To decide whether a call succeeded, first check whether the response contains an 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:
When an endpoint returns something other than JSON, the call throws a SyntaxError while parsing and you cannot get the raw content. Use fetch directly for these endpoints. Examples:
  • GET /guide returns Markdown.
  • GET /notes/{noteid}/render returns a long card image or a PDF.
  • GET /documents/{bookmd5}/pages/{index}/content/{contentId} returns an image.
  • GET /bundles/{bundleId}/files with a path returns the raw bytes of that file.
Choose how to read the response based on its content type:
For the behavior of /bridge/v1 and the other available paths, see Path system.

Complete example

Take excerpt-to-card workflows (vocabulary cards, for instance). A typical handler goes like this: the add-on reads the current context, pulls the relevant data out of the card, and finally marks the card according to what it actually did.