Closed Codepoet77 closed 9 years ago
@Codepoet77 what does the error say?
@Codepoet77 The field BrowseNodeId
is required to use this method.
I've updated this issue with the error message I see now.
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeLookup.html
var express = require('express'); var router = express.Router(); var amazon = require('amazon-product-api');
router.get('/', function (req, res) {
var credentials = { awsId: 'myId', awsSecret: 'mySecret', awsTag: 'myTag' };
amazon.createClient(credentials).browseNodeLookup({}, function (err, data) {
console.log(arguments);
if (err) {
res.send(err);
}
res.send(data);
});
});
module.exports = router;
This is the error I see:
TypeError: Cannot read property '0' of undefined
at /home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/lib/index.js:28:54
at Parser.
Thanks in advance.
Quick update. This appears to be a legit issue.
@kauegimenes thanks for the tip. You are right I thought there was a concept of root node but it appears as though that doesnt exist and each major category is a root node. Let me know if my understanding is incorrect.
All that being said below is response that I logged in index.js. I believe the issue we are treating the a browseNodeLookup response like a Item response. The items collections does not exist it in a browse node response and is why I am still getting the exception I listed above.
index.js line 28: results = resp[method + 'Response'].Items[0].Item;
browseNodeResponse: { BrowseNodeLookupResponse: { '$': { xmlns: 'http://webservices.amazon.com/AWSECommerceService/2011-08-01' }, OperationRequest: [ { RequestId: [ '96085264-4de7-11e5-96d5-e745bd0a6445' ], Arguments: [ { Argument: [ { '$': { Name: 'AWSAccessKeyId', Value: 'AKIAIWM6SAEG6BZXFT7Q' } }, { '$': { Name: 'AssociateTag', Value: 'fr056-20' } }, { '$': { Name: 'BrowseNodeId', Value: '9479199011' } }, { '$': { Name: 'Operation', Value: 'BrowseNodeLookup' } }, { '$': { Name: 'ResponseGroup', Value: 'BrowseNodeInfo' } }, { '$': { Name: 'Service', Value: 'AWSECommerceService' } }, { '$': { Name: 'Signature', Value: 'pFHRNSBafAhFj8CoQETsg27MnPTFkPW/YdlNsSzx9B8=' } }, { '$': { Name: 'Timestamp', Value: '2015-08-29T00:47:55.230Z' } } ] } ], RequestProcessingTime: [ '0.007022995' ] } ], BrowseNodes: [ { Request: [ { IsValid: [ 'True' ], BrowseNodeLookupRequest: [ { BrowseNodeId: [ '9479199011' ], ResponseGroup: [ 'BrowseNodeInfo' ] } ] } ], BrowseNode: [ { BrowseNodeId: [ '9479199011' ], Name: [ 'Luggage & Travel Gear' ], Children: [ { BrowseNode: [ { BrowseNodeId: [ '360832011' ], Name: [ 'Backpacks' ] }, { BrowseNodeId: [ '2204831011' ], Name: [ 'Briefcases' ] }, { BrowseNodeId: [ '166767011' ], Name: [ 'Diaper Bags' ] }, { BrowseNodeId: [ '2477385011' ], Name: [ 'Fashion Waist Packs' ] }, { BrowseNodeId: [ '15743181' ], Name: [ 'Gym Bags' ] }, { BrowseNodeId: [ '9971584011' ], Name: [ 'Laptop Bags' ] }, { BrowseNodeId: [ '15743251' ], Name: [ 'Luggage' ] }, { BrowseNodeId: [ '15743231' ], Name: [ 'Messenger Bags' ] }, { BrowseNodeId: [ '15743971' ], Name: [ 'Travel Accessories' ] }, { BrowseNodeId: [ '15744111' ], Name: [ 'Umbrellas' ] } ] } ], Ancestors: [ { BrowseNode: [ { BrowseNodeId: [ '7141124011' ], Name: [ 'Departments' ], IsCategoryRoot: [ '1' ], Ancestors: [ { BrowseNode: [ { BrowseNodeId: [ '7141123011' ], Name: [ 'Clothing, Shoes & Jewelry' ] } ] } ] } ] } ] } ] } ] } }
Was looking into this a little further and the promise works but the call back does not support browsenodelookup.
I'll dive into it today!
As mentioned before I am new Git and GitHub and was trying to learn how to fork and pull request but unfortunately need to continue to make progress on my project. This is change I made to make it work in index.js
In the call back only.
parseXML(body, function (err, resp) { if (method === 'BrowseNodeLookup' && resp[method + 'Response'].BrowseNodes && resp[method + 'Response'].BrowseNodes.length > 0) { results = resp[method + 'Response'].BrowseNodes[0].BrowseNode; } else { results = resp[method + 'Response'].Items[0].Item; } cb(null, results); });
The change is I added the if block.
Make a pull request then! It's bloody easy!
npm test
)This may help! https://guides.github.com/activities/forking/
I suggest you to get familiar with the markdown syntaxe. It is very useful since you can use it to write issue and comment.
OK thanks for all the info! I think I've managed to submit a PR.
Travis build failed with the same errors that others have seen in the past. Do you have any insight into what got it working again? I don't believe my change caused this (as far as I know).
Fix in PR #23
BrowseNodeLookup is not working as expected. This my code below:
It appears as though I get data back but I see this error in my console when I run my express NodeJS app on line 28:54 in index.js
Ill follow up with more info later if required.