Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Query Mailgun emails by custom variables / custom data
const util = require('util');
const _ = require('lodash');
const mailgun = require("mailgun-js");
async function queryByCustomData(data) {
let mg = mailgun({apiKey: process.env.MAILGUN_API_KEY});
let asyncGet = util.promisify(_.bind(mg.get, mg));
let response = await asyncGet(`/YOUR_MAIL_DOMAIN/events`, {
"user-variables": JSON.stringify(data),
});
return response;
}
queryByCustomData({is_special: true}).then((result) => {
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment