Here's a step-by-step guide to help you trigger mails in Mailmodo using APIs.
Using APIs with Mailmodo can help you to
- Integrate third-party apps and tools,
- Trigger automated campaigns from third-party apps,
- Set trigger endpoints for Journey emails.
What are API Endpoints?
Endpoints are used for interacting with server-side web APIs, as they specify where resources lie that can be accessed by third-party software. Usually, the access is via a URL to which HTTP requests are posted, and from which the response is expected.
Simply put, API Endpoints help you to get your apps to communicate with each other.
How to trigger mails via APIs:
Creating a POST request
Following are the parameters that you will need to create a POST request.
Endpoint
You can get the trigger endpoint URL from the corresponding Transactional Campaign in the following format:
https://api.mailmodo.com/api/v1/triggerCampaign/<campaign id>
When you enable a transactional campaign, you will receive this URL. By using the following steps, you may also get this URL for any campaign: Mailmodo Dashboard > Click the "Trigger" from campaigns tab. Choose the required campaign > setup steps
API key
An application programming interface key (API key) is a unique identifier used to authenticate a user, developer, or calling program to an API.
You can get API keys from Mailmodo using the following path:
Mailmodo Dashboard > Go to 'Settings' tab > API Keys
You need to provide the API key with the header 'mmApiKey' in the following format:
mmApiKey: <api key value>
Request
POST requests can be generated in multiple ways.
Here are sample cURL and axios request.
Sample CURL
curl --location --request POST 'https://api.mailmodo.com/api/v1/triggerCampaign/<campaign id>' \
--header 'mmApiKey: <api key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"subject":"Hi, this email is from api trigger",
"email": "apurv.gpt@gmail.com",
"data":{
"firstName" : "John",
}
}
Sample axios
var axios = require('axios');
var data = JSON.stringify(
{"subject":"Hi, this email is from api trigger",
"email":"apurv.gpt@gmail.com",
"data":{"firstName":"John"}});
var config = {
method: 'post',
url: 'https://api.mailmodo.com/api/v1/triggerCampaign/<campaign id>',
headers: {
'mmApiKey': '<api key>',
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Personalisation parameters:
You need to make the required personalisations in the parameters before using these. These have to be passed in the 'data' in the form of a 'key-value' pair and are meant to assign values to personalisation used in the subject line/ body of the mail.
For eg. {"firstName" : "John"}
Important notes
'Subject' is optional, if not provided, the original subject set in the campaign will be used
Campaign Id can be provided in the URL path or in the payload with the ‘campaignId’ key