// Send an email with the UniOne Web API
// Learn more -> https://docs.unione.io/en/web-api-ref#web-api
// First install node-fetch module: npm install node-fetch
import fetch from "node-fetch"
// Use eu1.unione.io for EU or us1.unione.io for US account
const base_url = 'https://eu1.unione.io/en/transactional/api/v1'
const headers = {
'Content-Type':'application/json',
'X-API-KEY':'YOUR-API-KEY'
};
const request = JSON.stringify({
message: {
recipients: [{
email: 'john@example.com',
substitutions: { to_name: 'John Smith' },
}],
body: { html: 'Hello, {{to_name}}!' },
subject: 'Hello from UniOne',
from_email: 'user@example.com',
},
});
fetch(base_url + '/email/send.json', {
method: 'POST',
body: request,
headers: headers
})
.then((response) => response.json())
.then(data => {
if(data.status == "success") {
console.log("Success, job_id=" + data.job_id);
}
});