donfanning
8/15/2018 - 1:05 PM

Using ASIN, get product details from amazon product advertising API and then print the price

Using ASIN, get product details from amazon product advertising API and then print the price

const { OperationHelper } = require('apac');
const config = require('./config');
const xmlParser = require('xml2json');

const opHelper = new OperationHelper(config.get('aws'));

/*
* Use the package convict for managing AWS settings and configure AWS setthings as follow
 aws: {
   awsId: '',
   awsSecret: '',
   assocId: ''
 }
*/

opHelper.execute('ItemLookup', {
  'ItemId': 'B0000WU53U', // change it wrt your needs
  'ResponseGroup': 'ItemAttributes,Offers'
})
  .then(xml => JSON.parse(xmlParser.toJson(xml.responseBody)))
  .then(json => {
    console.log(JSON.stringify(json));
    let price = json.ItemLookupResponse.Items.Item.Offers.Offer.OfferListing.Price.Amount;
    console.log('Amount = ' + price);

    // let price = json.ItemLookupResponse.Items.Item.Offers.Offer.OfferListing.Price.Amount / 100 ;
    // let regPrice = json.ItemLookupResponse.Items.Item.ItemAttributes.ListPrice.Amount / 100 ;

    console.log('Results object: ', {
      asin: 'B00E54ZKDY',
      price: price
    });
    return {
      asin: 'B00E54ZKDY',
      price: price
    };
  })
  .catch((err) => {
    console.error('Something went wrong! ', err);
  });