Generating emails
1. Prerequisites
Before you start generating your first email with Mailsyrup API make sure you have setup it correctly and you have generated brand and API key.
2. Choose the template
Please check the section on templates.
You should have at least url of endpoint you want to generate, now you can use your favorite programming language to make the API request.
In the example we will use v1/templates/notification
endpoint.
3. Generate email
Python example
Install requests
package:
Then:
import requests
response = requests.post(
"https://api.mailsyrup.com/v1/templates/notification",
headers={
"Content-Type": "application/json",
"X-API-Key": "$YOUR_API_KEY"
},
json={
"brandId": "$YOUR_BRAND_ID",
"content": {
"header": "This is my header",
"paragraphs": [
"This is my first paragraph"
]
}
}
).json()
print(response['text']) # generated email as a text
print(response['html']) # generated email as a html
TypeScript example
async function generateEmail() {
const response = await fetch(
"https://api.mailsyrup.com/v1/templates/notification",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "$YOUR_API_KEY",
},
body: JSON.stringify({
brandId: "$YOUR_BRAND_ID",
content: {
header: "This is my header",
paragraphs: ["This is my first paragraph"],
},
}),
}
);
return response.json();
}
generateEmail()
.then(async (email) => {
console.log(email.text); // generated email as a text
console.log(email.html); // generated email as html
})
.catch((error) => {
console.log("Error", error);
});