Skip to content

Autosaves

The Autosave feature in the Topol Plugin helps ensure users never lose their work due to unexpected interruptions. They provide a reliable safety net by automatically storing draft versions of the current template at configurable intervals.

This feature is easy to enable and supports full integration with custom backend storage using REST API endpoints.

Enabling Autosaves

To activate autosaving, configure the following setting in your TOPOL_OPTIONS:

ts
enableAutosaves: true,

By default, autosaves occur at a set interval (60 seconds) and are sent to your API backend.

Configuring Autosave Frequency

You can define how often the autosave should occur using the autosaveInterval parameter. The value is provided in seconds, and the minimum supported interval is 30 seconds.

ts
autosaveInterval: 60 * 3, // Saves every 3 minutes

Autosaves are also identifiable by adding Current user information as described here.

API Integration for Autosaves

To support autosaves fully, your backend should implement the following API endpoints. These allow the Topol Plugin to save, retrieve, and list autosaved drafts associated with a specific template and user.

WARNING

Before implementing the endpoints, check how to work with API endpoints.

Called to fetch a list of all autosaved drafts for the current template/user.

  • URL: /{API.AUTOSAVES}
  • Method: GET
  • Params: key, hostname, templateId, uuid

Response:

json
{
  "success": true,
  "data": [
    {
      "uid:": "userID",
      "key:": "autosaveKey", //used in GET_AUTOSAVE param when retrieving autosave
      "time:": "2025-05-01T12:00:00Z", // ISO 8601 time
      "created_by": {
        "user_id": 0,
        "name": "John Doe",
        "profile_photo_url": "https://example.com/profile.jpg"
      }
    }
  ]
}

If created_by is omitted, editor will show only the timestamp. User info is optional but enhances UX.

Called by the editor when a new autosave is created. You should use this data to save the JSON of the template, the time when autosave was created, the user ID, and a unique autosave identifier. This data is then used when retrieving autosave.

  • URL: /{API.AUTOSAVES}
  • Method: POST

Request:

json
{
  "definition": "{...}", // JSON representing the email template (MJML in JSON)
  "key": "api key value",
  "hostname": "origin",
  "templateId": "id of the template",
  "uuid": "userId",
  "current_user_id": "id of the current user" // provided in the current user identification object
}

Response:

HTTP 200 OK

Called to retrieve a previously saved autosave by its unique key. This endpoint automatically appends /{autosave-key} to the GET_AUTOSAVE API path.

  • URL: /{API.GET_AUTOSAVE}/{autosave-key}
  • Method: GET
  • Params: key, hostname, templateId, uuid

Response:

json
{
  "success": true,
  "data": {
    "template": "{...}" // JSON format of the saved template
  }
}