Skip to content
Open in

API Authorization ​

The apiAuthorizationHeader option attaches an authorization header to the API requests the Plugin makes to your endpoints. Use it when your feeds, products, templates or file storage endpoints sit behind token-based access control.

Which requests carry the header ​

The header is added to requests aimed at the endpoints you configure through the api option. Three groups are deliberately excluded:

  • Topol's own backend calls, which carry their own plugin key. This covers HTML rendering and preview, test sends, template loading, signed upload URLs, and every AI endpoint.
  • Giphy search, used by the GIF block.
  • Vimeo oEmbed lookups, used by the video block.

Setting the authorization header ​

Define the header inside TOPOL_OPTIONS when initializing the Plugin. There are two approaches.

1. Using standard authorization header ​

This is the most common method (e.g., with Bearer tokens):

js
apiAuthorizationHeader: "Bearer your_token"

This configuration results in HTTP headers like:

Authorization: Bearer your_token

2. Using custom header names ​

If your backend expects a non-standard header, or the token has to travel under a custom key, define the header as an object:

js
apiAuthorizationHeader: {
  "X-Auth-Token": "your_custom_token"
}

This configuration sends:

X-Auth-Token: your_custom_token

The object form accepts more than one entry, and every key becomes its own header:

js
apiAuthorizationHeader: {
  "X-Auth-Token": "your_custom_token",
  "X-Tenant-Id": "acme"
}

Updating authorization tokens dynamically ​

When the token needs to be refreshed after expiration or a re-authentication, editor.updateApiAuthorizationHeader() updates it without reinitializing the Plugin:

js
editor.updateApiAuthorizationHeader(new_token);

new_token can be a string or an object that provides header name and the value:

js
// either string format (standard)
editor.updateApiAuthorizationHeader("Bearer new_token_value");
// or object format (custom header)
editor.updateApiAuthorizationHeader({
  "X-Auth-Token": "new_token_value"
});

INFO

Keep the shape consistent with what was passed at initialization:

  • A string replaces everything stored so far and is sent as Authorization, so custom headers passed at initialization are no longer sent.
  • An object is merged into the headers passed earlier. Send only the headers that changed, and the others keep their values. To remove a header, send it with null, e.g. { "X-Tenant-Id": null }.

The configured header is stripped from the options object before it is logged or persisted, so the token does not travel with saved template metadata.