Send an Email from notification template

Sends an email based on a specified notification template.

Request

HTTP Request

POST /node/api/notification-templates/send

Body parameters

Parameter Type Description

subjectTemplate

String

Email subject template.

contentTemplate

String

Email content template.

templateVars

String

Template variables as a JSON object. You can see the format in the request body example below.

sendParams

String

Email message configuration. You can find more information in the Nodemailer documentation.

entityId

String

ID entity from which the script takes variable value.

entityType

String

Entity type. 1 for object, 2 for link.

Request body

Request body contains email settings and contents.

{
  "entityId": "67f7e77a2b10d179db91dfa6",
  "subjectTemplate": "Subject {{entityName}}",
  "contentTemplate": "<h1>{{foo}}</h1><ul>{{#bar.a}}{{#x}} <li>{{x}}</li>{{/x}}{{/bar.a}}</ul>",
  "templateVars": {
    "foo": "This is foo var!",
    "bar": {
      "a": [{
          "x": 1
        },
        {
          "x": 22
        },
        {
          "x2": 20
        }
      ]
    }
  },
  "sendParams": {
    "to": "user@example.com"
  }
}

Response

Response body is empty.

Example

Request

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/notification-templates/send

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
  "entityId": "67f7e77a2b10d179db91dfa6",
  "subjectTemplate": "Subject {{entityName}}",
  "contentTemplate": "<h1>{{foo}}</h1><ul>{{#bar.a}}{{#x}} <li>{{x}}</li>{{/x}}{{/bar.a}}</ul>",
  "templateVars": {
    "foo": "This is foo var!",
    "bar": {
      "a": [{
          "x": 1
        },
        {
          "x": 22
        },
        {
          "x2": 20
        }
      ]
    }
  },
  "sendParams": {
    "to": "user@example.com"
  }
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/notification-templates/send";
let auth = "Basic " + btoa(login + ":" + password);

let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Authorization", auth);

let data = JSON.stringify({
  "entityId": "67f7e77a2b10d179db91dfa6",
  "subjectTemplate": "Subject {{entityName}}",
  "contentTemplate": "<h1>{{foo}}</h1><ul>{{#bar.a}}{{#x}} <li>{{x}}</li>{{/x}}{{/bar.a}}</ul>",
  "templateVars": {
    "foo": "This is foo var!",
    "bar": {
      "a": [{
          "x": 1
        },
        {
          "x": 22
        },
        {
          "x2": 20
        }
      ]
    }
  },
  "sendParams": {
    "to": "user@example.com"
  }
});

let requestOptions = {
    method: "POST",
    headers: headers,
    body: data
};

fetch(saymonHostname + path, requestOptions)
    .then(response => response.text())
    .then(result => console.log(result))
    .catch(error => console.log("error", error));
const http = require("http");

let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/notification-templates/send";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");

let options = {
    "method": "POST",
    "hostname": saymonHostname,
    "headers": {
        "Authorization": auth,
        "Content-Type": "application/json"
    },
    "path": path
};

let req = http.request(options, function (res) {
    let chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function (chunk) {
        let body = Buffer.concat(chunks);
        console.log(body.toString());
    });

    res.on("error", function (error) {
        console.error(error);
    });
});

let data = JSON.stringify({
  "entityId": "67f7e77a2b10d179db91dfa6",
  "subjectTemplate": "Subject {{entityName}}",
  "contentTemplate": "<h1>{{foo}}</h1><ul>{{#bar.a}}{{#x}} <li>{{x}}</li>{{/x}}{{/bar.a}}</ul>",
  "templateVars": {
    "foo": "This is foo var!",
    "bar": {
      "a": [{
          "x": 1
        },
        {
          "x": 22
        },
        {
          "x2": 20
        }
      ]
    }
  },
  "sendParams": {
    "to": "user@example.com"
  }
});

req.write(data);
req.end();
import requests

login = <...>
password = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/notification-templates/send"
body = {
  "entityId": "67f7e77a2b10d179db91dfa6",
  "subjectTemplate": "Subject {{entityName}}",
  "contentTemplate": "<h1>{{foo}}</h1><ul>{{#bar.a}}{{#x}} <li>{{x}}</li>{{/x}}{{/bar.a}}</ul>",
  "templateVars": {
    "foo": "This is foo var!",
    "bar": {
      "a": [{
          "x": 1
        },
        {
          "x": 22
        },
        {
          "x2": 20
        }
      ]
    }
  },
  "sendParams": {
    "to": "user@example.com"
  }
}

response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)