Skip to content

Instantly share code, notes, and snippets.

@thefln
Created May 14, 2018 15:21
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 thefln/8ac281c11c1f144df00ff30079afa6c4 to your computer and use it in GitHub Desktop.
Save thefln/8ac281c11c1f144df00ff30079afa6c4 to your computer and use it in GitHub Desktop.
var request = require('request');
exports.handler = function(event, context, callback) {
// buttercms send webhook data as POST request
if(event.httpMethod !== 'POST' || !event.body) {
return callback(null, {
statusCode: 200,
body: ''
});
}
const payload = JSON.parse(event.body);
if(payload.data.page_type !== 'product') {
return callback(null, {
statusCode: 200,
body: ''
});
}
request.post({
url: 'https://'+ process.env.SNIPCART_API_KEY +':@app.snipcart.com/api/products',
json: true,
body: {
fetchUrl: 'https://snipcart-buttercms-demo.netlify.com/.netlify/functions/snipcart_json_crawler',
}
}, function(err, res, body) {
callback(null, {
statusCode: 200,
body: '',
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment