Created
January 3, 2020 19:16
-
-
Save colllin/b0dd7ee084d9a69c8ac91b937d3dcf0f to your computer and use it in GitHub Desktop.
Query Mailgun emails by custom variables / custom data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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