DocumentationSDK on GitHub

Documentation Get started

JavaScript quickstart

Mount an editor and export your first email as HTML.

On this page

1. Get your editor key

In the dashboard, create or select an editor and copy its public key. Allow your application’s origin, including the scheme and port: for example, https://app.example.com.

2. Install the SDK

bash
npm install @weavour/editor

3. Add a container

Give the container an explicit height. Mount after the element exists.

html
<div id="email-editor" style="height: 700px"></div>

4. Mount and export

Replace the key and IDs with your own. Pass organizationId when users share an organization’s library; omit it for a personal library. Run this code in the browser.

typescript
import { mount } from '@weavour/editor';

try {
  const editor = mount('#email-editor', {
    editorKey: 'YOUR_PUBLIC_EDITOR_KEY',
    userId: 'user-123',
    organizationId: 'organization-456',
    locale: 'en',
    onError(error) {
      console.error(error);
    },
  });

  await editor.ready;
  const { html, text, subject, preheader } = await editor.exportHTML();
  // Pass these fields to your application's delivery workflow.
} catch (error) {
  console.error('The editor could not load or export:', error);
}

Without a bundler

Use the versioned browser script to access Weavour.mount().

html
<div id="email-editor" style="height: 700px"></div>
<script src="https://weavour.com/editor/sdk/0.1.12/editor.js"></script>
<script>
  async function openEditor() {
    const editor = Weavour.mount('#email-editor', {
      editorKey: 'YOUR_PUBLIC_EDITOR_KEY',
      userId: 'user-123',
      onError: console.error,
    });
    await editor.ready;
    return editor;
  }
  openEditor().catch(console.error);
</script>

Next: save the user’s work

Need help? Contact us