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.

Revisions

  1. sawantuday created this gist Mar 25, 2017.
    32 changes: 32 additions & 0 deletions APAI_Webtask.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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")
    });
    }