Skip to content

Instantly share code, notes, and snippets.

@navdeepsingh
Last active February 21, 2019 06:07
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 navdeepsingh/07c77d89165151a1ee9ca8559ac51d16 to your computer and use it in GitHub Desktop.
Save navdeepsingh/07c77d89165151a1ee9ca8559ac51d16 to your computer and use it in GitHub Desktop.
Post to Omnisend
/*****************/
//@TODO Update Omnisend separately with list id
/*****************/
// An object of options to indicate where to post to
var options = {
"method": "POST",
"protocol": 'https:',
"hostname": 'api.omnisend.com',
"path": '/v3/contacts',
"headers": {
"Content-Type": "application/json",
"X-API-KEY": process.env.OMNISEND_API_KEY
}
};
let postData = {
email: email,
lists: [{ listID: process.env.OMNISEND_LIST_ID }],
status: 'subscribed',
statusDate: new Date().toISOString()
}
let stringPostData = JSON.stringify(postData);
console.log(stringPostData);
//Send post request to omnisend
var 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('response end: ', body.toString());
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(stringPostData);
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment