Last active
December 13, 2016 02:58
-
-
Save LosantGists/bf4423a9a456ad3d694667988953f21a to your computer and use it in GitHub Desktop.
Lambda function to invoke Losant webhook.
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
var https = require('https'); | |
exports.handler = (event, context, callback) => { | |
var postData = JSON.stringify(event); | |
var options = { | |
hostname: 'triggers.losant.com', | |
port: 443, | |
path: '/webhooks/my-webhook-id', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
'Content-Length': Buffer.byteLength(postData) | |
} | |
}; | |
var req = https.request(options, (res) => { | |
console.log(`STATUS: ${res.statusCode}`); | |
console.log(`HEADERS: ${JSON.stringify(res.headers)}`); | |
res.setEncoding('utf8'); | |
res.on('data', (chunk) => { | |
console.log(`BODY: ${chunk}`); | |
}); | |
res.on('end', () => { | |
callback(); | |
}); | |
}); | |
req.on('error', (e) => { | |
console.log(`problem with request: ${e.message}`); | |
callback(); | |
}); | |
// write data to request body | |
req.write(postData); | |
req.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment