Created
May 14, 2018 15:21
-
-
Save thefln/8ac281c11c1f144df00ff30079afa6c4 to your computer and use it in GitHub Desktop.
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 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