arifulhb / amazon-pa-api50

Amazon Product Advertising API v5.0 for JavaScript and NodeJs
https://www.npmjs.com/package/amazon-pa-api50
MIT License
29 stars 9 forks source link

Resource filters not working? #2

Closed moggiex closed 4 years ago

moggiex commented 4 years ago

Howdy,

No matter what I set for the resources, I always seem to get the same response back for any ASIN.

Try B000Y854WC on the UK site, eg below:

api.getItemById(['B000Y854WC'], {
        // resources: resourceList,
        resources: ["ItemInfo.ExternalIds", "ItemInfo.ProductInfo"],
        // condition: condition.Any
    })

The response is always the same, regardless of what resource value is set.

console.log('data', response.data)
console.log('data', response.data.ItemsResult)
console.log('data', response.data.ItemsResult.Items[0].ItemInfo)
data { ItemsResult: { Items: [ [Object] ] } }
data { Items:
   [ { ASIN: 'B000Y854WC',
       DetailPageURL: 'https://www.amazon.co.uk/dp/B000Y854WC?tag=chromeapp02-21&linkCode=ogi&th=1&psc=1',
       ItemInfo: [Object] } ] }
data { Title:
   { DisplayValue: 'Campingaz Camp Bistro 2 Camping Stove, 1 Flame Portable Gas Cartridge Cooker, Runs on Campingaz CP 250 Cartridges, 2200 WW',
     Label: 'Title',
     Locale: 'en_GB' } }

Am I doing something wrong here @arifulhb?

moggiex commented 4 years ago

Having a dig around.

src/index.js line 33

if (params.parameters !== null || params.parameters !== 'undefined') {
      getItemsRequest.Resources = params.parameters
    }

This doesn't appear to be being set.

If I force this with:

if (params.parameters !== null || params.parameters !== 'undefined') {
      getItemsRequest.Resources = params.parameters
    }
 getItemsRequest.Resources= ["ItemInfo.ExternalIds", "ItemInfo.ProductInfo"];

The response is:

data { Items:
   [ { ASIN: 'B000Y854WC',
       DetailPageURL: 'https://www.amazon.co.uk/dp/B000Y854WC?tag=chromeapp02-21&linkCode=ogi&th=1&psc=1',
       ItemInfo: [Object] } ] }
data { ExternalIds:
   { EANs: { DisplayValues: [Array], Label: 'EAN', Locale: 'en_US' },
     UPCs: { DisplayValues: [Array], Label: 'UPC', Locale: 'en_US' } },
  ProductInfo:
   { Color: { DisplayValue: 'Blue', Label: 'Color', Locale: 'en_GB' },
     IsAdultProduct: { DisplayValue: false, Label: 'IsAdultProduct', Locale: 'en_US' },
     ItemDimensions: { Weight: [Object] },
     Size: { DisplayValue: 'N/A', Label: 'Size', Locale: 'en_GB' },
     UnitCount: { DisplayValue: 1, Label: 'NumberOfItems', Locale: 'en_US' } } }
moggiex commented 4 years ago

Found the issue and pushed an update over.

if (params.resources !== null || params.resources !== 'undefined') {

arifulhb commented 4 years ago

Hi @moggiex , Thanks for finding the issue and the solution. Can you make a PR, so that I can get your update?

moggiex commented 4 years ago

Hi,

can you not see https://github.com/moggiex/amazon-pa-api50/commit/501ddef8230da7e32944a99d5cd62a9a7edf36e3 or https://github.com/moggiex/amazon-pa-api50/commit/000c3f2a79c135d406fedb2a8e9e6414435a15ba ?

Matt

moggiex commented 4 years ago

Ps @arifulhb I only use git for personal projects, so NFI on what a 'PR' is

arifulhb commented 4 years ago

@moggiex No worries then. I'll re-implement your solution and update my source.

Meanwhile, you can check this about PR https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests

Thanks for your help.

arifulhb commented 4 years ago

api.getItemById(['B000Y854WC'], { // resources: resourceList, resources: ["ItemInfo.ExternalIds", "ItemInfo.ProductInfo"], // condition: condition.Any })

I found the issue. You actually sending resources in parameter, which actually should be parameters. Please check this doc https://github.com/arifulhb/amazon-pa-api50#get-a-single-or-array-of-products-via-asin

let resourceList = parameters.getItemInfo
resourceList = resourceList
  .concat(parameters.getImagesPrimary)

api.getItemById(['B079JD7F7G'], {
  parameters: resourceList, // <<<< Follow this.
  condition: condition.Any
}).then((response) => {
  console.log(' ===== find by Item ids =====')
  console.log('data', response.data)
}).catch((error) => {
  console.log('Error: ', error)
})