Skip to content

Instantly share code, notes, and snippets.

@sawantuday
Created March 25, 2017 16:10
Show Gist options
  • Save sawantuday/72fbd6717c45e49817cf02b6c4ff7f24 to your computer and use it in GitHub Desktop.
Save sawantuday/72fbd6717c45e49817cf02b6c4ff7f24 to your computer and use it in GitHub Desktop.
Webtask module for Amazon Products API
module.exports = function (cb) {
var amazon = require('amazon-product-api');
var client = amazon.createClient({
awsId: "Affiliate ID",
awsSecret: "AWS Secret",
awsTag: "affiliate-tag",
locale: "IN"
});
client.itemLookup({
idType: 'ASIN',
itemId: 'B01DWAVO2W',
responseGroup: 'ItemAttributes,Offers,Images,Large',
domain: 'webservices.amazon.in'
}).then(function (results) {
// console.log("callback sucess")
cb(null, {
'ASIN': results[0].ASIN[0],
'title': results[0].ItemAttributes[0].Title[0],
'url': results[0].DetailPageURL[0],
'lImg': results[0].LargeImage[0].URL[0],
'mImg': results[0].MediumImage[0].URL[0],
'listPrice': results[0].ItemAttributes[0].ListPrice[0].FormattedPrice[0],
'sellPrice': results[0].Offers[0].Offer[0].OfferListing[0].Price[0].FormattedPrice[0],
'available': results[0].Offers[0].Offer[0].OfferListing[0].AvailabilityAttributes[0].AvailabilityType[0] == 'now' ? 'yes' : 'no',
'similar': results[0].SimilarProducts[0].SimilarProduct,
})
// console.log(JSON.stringify(results));
}).catch (function (err) {
console.log("error")
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment