Last active
June 13, 2019 06:26
-
-
Save unknownliviu/a653bed0ad723410255b92a1244a3ba7 to your computer and use it in GitHub Desktop.
Simple Sparkpost api usage
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
console.log('Loading function'); | |
var http = require("https"); | |
var fs = require('fs'); | |
var options = { | |
"method": "POST", | |
"hostname": "api.sparkpost.com", | |
"path": "/api/v1/transmissions?num_rcpt_errors=3", | |
"headers": { | |
"Content-Type": "application/json", | |
"Accept": "application/json", | |
"Authorization": "<api_key>", | |
"cache-control": "no-cache" | |
} | |
}; | |
async function iterate() { | |
let emails = ['[email protected]', '[email protected]'] | |
let recipients = []; | |
for (var i = 0; i < emails.length; i++) { | |
let email = emails[i]; | |
recipients.push({ | |
address: email | |
}); | |
let req = http.request(options, function(res) { | |
var chunks = []; | |
res.on("data", function(chunk) { | |
chunks.push(chunk); | |
}); | |
res.on("end", function() { | |
var body = Buffer.concat(chunks); | |
console.log(body.toString()); | |
}); | |
}); | |
req.write(JSON.stringify({ | |
campaign_id: 'some_campaign', | |
recipients: recipients, | |
content: { | |
template_id: "<template_id>" | |
} | |
})); | |
req.end(); | |
} | |
} | |
iterate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment