Skip to content

Instantly share code, notes, and snippets.

@colllin
Created January 3, 2020 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colllin/b0dd7ee084d9a69c8ac91b937d3dcf0f to your computer and use it in GitHub Desktop.
Save colllin/b0dd7ee084d9a69c8ac91b937d3dcf0f to your computer and use it in GitHub Desktop.
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