Skip to content

Autosaves

You can take advantage of built-in autosaves to provide better experience for your users.

First you need to enable the autosaves on options using

js
enableAutosaves: true;

We can also set custom autosave interval using: (in seconds). Minimal interval is 30 seconds.

ts
autosaveInterval: 60 * 3; //seconds

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

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

List autosaves

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

This endpoint is called when listing all autosaves.

Response:

json
{
  "success": true,
  "data": [
    {
      "uid:": "userID",
      "key:": "autosaveKey", //used in GET_AUTOSAVE param when retrieving,
      "time:": "ISO 8601 time",
      "created_by": {
        "user_id": 0,
        "name": "John Doe",
        "profile_photo_url": "profile_picture_url"
      } // optional, Editor can simply display timestamp withou user identification
    }
  ]
}

Create autosave

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

This endpoint is called when autosave is created.

You should use this data to save JSON of the template, time when autosave was created, user id, and unique autosave identifier. This data are then used when retrieving autosave.

Request:

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

Expected Response: STATUS 200

List autosave

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

INFO

This endpoint appends /{autosave-key} automatically

This endpoint is called when retrieving created autosave.

Response:

json
{
  "success": true,
  "data": {
    "template": "jsonTemplate"
  }
}