Skip to content
Open in

Getting Started with Topol Plugin ​

Embedding Topol Plugin takes two steps: create an API token, then add a container element and a short script to your page. A third step, nonce authentication, is what we recommend before real users open the editor. Everything else is optional and can be layered on later.

Using React, Vue, or another framework?

Step 1 applies to every integration. Step 2 does not; follow NPM & Frameworks instead.

Step 1: Create your API token ​

Log into your Topol Account, open the API Tokens tab and click + New API Token. The page that opens creates the token that authorizes the Topol Plugin in your application.

Newly created API token with its Public API key and Secret key

The token comes with two keys, shown in the API Keys tab: the Public API key goes into the Plugin configuration in your page, and the Secret key authorizes direct calls to the Topol API and must never be exposed in client-side code.

With the token created, switch to the Configuration tab and add every domain where the Plugin will run to the Allowed domains list.

Allowed domains list in the token's Configuration tab

WARNING

The token only works on the domains listed in its configuration.

Step 2: Add the Plugin to your application ​

With the API key ready, the Plugin goes into your page in two pieces: a container element and a script that configures and starts the editor. (In a framework app, the NPM packages replace this setup.)

Let your coding agent do it recommended ​

The fastest way to integrate is to hand the job to your AI coding agent. The official topol-editors-integration skill teaches it the current API, so it writes the integration from the source of truth instead of from older examples it may have seen.

1. Install the skills in the project that will embed the editor:

claude
/plugin marketplace add TOPOL-io/skills
/plugin install topol-editors@topol
bash
npx skills@latest add TOPOL-io/skills

The skills are plain markdown in TOPOL-io/skills, so you can read what the agent will do before it runs, or point any other agent at the files directly.

2. Ask for the integration, in your own words:

text
Add the Topol email editor to this app

The agent adds the editor through the NPM package that fits your framework, or with the script tag below when the page has no build step. It mounts the editor in a sized container, wires onSave and onEditorError, reads the API key from your environment configuration, and runs your type-check and build.

3. Finish what only you can decide: put the Public API key from Step 1 where the agent tells you, decide where saved templates are stored, and open the page once to see the editor load. Then go on to Step 3.

Add it by hand ​

First, add this HTML where you want the editor to appear. The container needs an explicit width and height, otherwise the editor has no space to render:

html
<!-- This is the container where the Topol Plugin will load -->
<div id="app" style="position: absolute; width: 100%; height: 100%;"></div>

Next, load the Plugin script and initialize it:

html
<!-- Load the Topol Plugin script -->
<script
  src="https://v4.email-assets.topol.io/loader/build.js"
  type="text/javascript"
></script>

<!-- Configure and initialize the Topol Plugin -->
<script>
  const TOPOL_OPTIONS = {
    authorize: {
      apiKey: "YOUR_API_KEY", // Replace with your Public API key from step 1
      entityId: "UserID", // Any unique ID you assign for the user
    },
  };

  // Create the editor instance. Options go under `config`,
  // callbacks are top-level properties passed next to it.
  const editor = TopolEmailEditor({
    config: TOPOL_OPTIONS,
    onSave: function ({ json, html }) {
      // This function runs when the user saves
      // You can handle the JSON and HTML data here (e.g., save to your server)
    },
  });

  // Render the editor into the container
  editor.render("#app");

  // Optional: Load a template into the editor on start
  fetch("https://tlapi.github.io/topol-editor/templates/1.json")
    .then((response) => response.text())
    .then((template) => {
      editor.load(template);
    });
</script>

Important notes:

  • The apiKey is the Public API key from Step 1.
  • The entityId can be any unique string that identifies your user (letters, numbers, _ or -; other characters are rejected at init). It determines where that user's images are stored and counts as one unique user for monthly billing. Typically, one entityId corresponds to one client of your app, CRM, ESP, etc. Reusing a single entityId across several people counts them as one user and gives them a shared image library.
  • The editor runs in an iframe created by render(). Methods on the instance (load, save, and the rest of the instance reference) can be called right after render(); each call waits for the editor to finish initializing and returns a Promise.
  • The example also loads a sample template from a URL. Replace it with your own template, or drop that optional block to start the editor empty.

Step 3: Authorize with nonces recommended ​

The API key from Step 1 is enough to get the editor on screen, but it sits in your page source and never expires. For real users we recommend nonce authentication: your backend signs a short-lived nonce for each signed-in user with the Secret key, and the editor runs on that. A nonce is bound to one user, expires within the hour, and stops working the moment you rotate the Secret key.

It takes two additions and changes nothing else in your integration:

  1. A backend endpoint that signs a nonce for the signed-in user with the Secret key. It makes no call to Topol.
  2. A getNonce callback next to config that fetches the nonce from that endpoint.
js
import { createHash, createHmac } from "node:crypto";

function signTopolNonce(entityId) {
  const key = createHash("sha256").update(process.env.TOPOL_SECRET_KEY).digest("hex");
  const payload = {
    credPk: process.env.TOPOL_API_KEY, // the Public API key from Step 1
    entityId: String(entityId), // same value as authorize.entityId
    exp: Math.floor(Date.now() / 1000) + 3600, // one hour at most
  };
  const body = Buffer.from(JSON.stringify(payload)).toString("base64url");
  const signature = createHmac("sha256", key).update(body).digest("base64url");
  return `nc_${body}.${signature}`;
}

// Only for signed-in users
app.post("/api/topol/nonce", requireLogin, (req, res) => {
  res.json({ nonce: signTopolNonce(req.user.id) });
});
js
const editor = TopolEmailEditor({
  config: TOPOL_OPTIONS,
  async getNonce() {
    const response = await fetch("/api/topol/nonce", { method: "POST" });
    if (!response.ok) throw new Error("Could not get a Topol nonce");
    return (await response.json()).nonce;
  },
  // ...your other callbacks
});

The Secret key stays on your server: never send it to the browser or sign nonces there. A Secret key that doesn't start with sk_ (issued before the prefix existed) needs sk_ put in front of it before hashing.

Nonce Authentication is the full guide: the nonce format, PHP signing code, the NPM package variants, and how refresh and errors behave. If you integrated with a coding agent, ask it to "add Topol nonce authentication" and it writes both pieces.

INFO

Running into trouble while implementing the Topol Plugin? Contact our support team here and we'll help you get it working.