Last active
February 21, 2019 06:07
-
-
Save navdeepsingh/07c77d89165151a1ee9ca8559ac51d16 to your computer and use it in GitHub Desktop.
Revisions
-
navdeepsingh revised this gist
Feb 21, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ /*****************/ //@TODO Update Omnisend separately with list id /*****************/ // An object of options to indicate where to post to var options = { "method": "POST", "protocol": 'https:', -
navdeepsingh created this gist
Feb 21, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ /*****************/ //@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();