jorgerosal / amazon-paapi

🔥Amazon Product Advertising API for NodeJs. A PAAPI 5.0 sdk wrapper.
https://webservices.amazon.com/paapi5/documentation/
MIT License
80 stars 19 forks source link

Need help with usage #17

Open RapahelS opened 2 years ago

RapahelS commented 2 years ago

Hello, I am trying to use the amazon-paapi. If I call the paapi and print the result to the terminal, I am getting following response. exports { ItemsResult: exports { Items: [ [exports] ] } }

How can I get and use the api response? Do you have an example that shows how to call the code and how to get the result in json format?

RapahelS commented 2 years ago

Sorry. I forgot to mention that I am trying to use the searchItems example

hardcore commented 2 years ago

Hello,

I use Marketplace www.amazon.de (Germany) and I have the same problem :-(

Hope someone can help us!

Thanks a lot!

jorgerosal commented 2 years ago

Hi, were you able to get a solution? If you could send your code here so we can check? Thanks!

RapahelS commented 2 years ago

Yes, I found a solution. This is the code I ended up using:

amazonPaapi.js

`const amazonPaapi = require("amazon-paapi");

const commonParameters = { AccessKey: "XXXXXXX", SecretKey: "XXXXXXX", PartnerTag: "XXXXXX", PartnerType: "Associates", Marketplace: "www.amazon.de", };

let requestParameters = { SearchIndex: "All", ItemCount: 5, Resources: [ "Images.Primary.Large", "ItemInfo.Title", "Offers.Listings.Price", "Offers.Listings.Availability.Type", "CustomerReviews.StarRating", "BrowseNodeInfo.BrowseNodes.SalesRank", "ItemInfo.Features", "ItemInfo.ProductInfo", "ItemInfo.TechnicalInfo", ], };

exports.getItemsFromAmazonByKeyword = (productsArray) => { return new Promise(async (resolve) => { requestParameters.Keywords = productsArray; try { let data = await amazonPaapi.SearchItems( commonParameters, requestParameters ); resolve(data); } catch (error) { console.log("paapi Error: " + error); reject(error); } }); };`

app.js

... `async function searchProductsByKeyword(keyword) { let data = await AmazonUtils.getItemsFromAmazonByKeyword(keyword);

return data; }` ...

Please let me know if there is a more elegant way.

marco910 commented 2 years ago

@RapahelS I'm having the same issue. How did you manage the import of getItemsFromAmazonByKeyword in app.js?

EliaTolin commented 2 years ago

I'm having the same issue. Have you fix?

tka85 commented 1 year ago

Using console.log directly on the response object does not display the full structure because contains nested objects, possibly with non-enumerable properties.

To better inspect the entire response object, you need to use JSON.stringify() to convert the object into a readable string format. Use this instead:

console.log(JSON.stringify(data, null, 2));

This did it for me.