Code Monkey home page Code Monkey logo

Comments (13)

masterT avatar masterT commented on June 14, 2024

@Codepoet77 what does the error say?

from amazon-product-api.

kaue avatar kaue commented on June 14, 2024

@Codepoet77 The field BrowseNodeId is required to use this method.

from amazon-product-api.

Codepoet77 avatar Codepoet77 commented on June 14, 2024

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. (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/lib/xml2js.js:460:18)
at Parser.emit (events.js:95:17)
at Object.onclosetag (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/lib/xml2js.js:421:26)
at emit (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/node_modules/sax/lib/sax.js:625:33)
at emitNode (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/node_modules/sax/lib/sax.js:630:3)
at closeTag (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/node_modules/sax/lib/sax.js:874:5)
at Object.write (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/node_modules/sax/lib/sax.js:1314:29)
at Parser.exports.Parser.Parser.parseString (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/lib/xml2js.js:479:31)
at Parser.parseString (/home/andrew/Documents/ppi2/source/server/node_modules/amazon-product-api/node_modules/xml2js/lib/xml2js.js:7:59)

Thanks in advance.

from amazon-product-api.

Codepoet77 avatar Codepoet77 commented on June 14, 2024

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' ] } ] } ] } ] } ] } ] } ] } }

from amazon-product-api.

Codepoet77 avatar Codepoet77 commented on June 14, 2024

Was looking into this a little further and the promise works but the call back does not support browsenodelookup.

from amazon-product-api.

masterT avatar masterT commented on June 14, 2024

I'll dive into it today!

from amazon-product-api.

Codepoet77 avatar Codepoet77 commented on June 14, 2024

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.

from amazon-product-api.

masterT avatar masterT commented on June 14, 2024

Make a pull request then! It's bloody easy!

  1. Fork the repo
  2. Change de code (make sure the tests pass with npm test)
  3. Commit your changes and push it
  4. Go on this repo in pull request tab and create a new PR.
    😊

from amazon-product-api.

masterT avatar masterT commented on June 14, 2024

This may help!
https://guides.github.com/activities/forking/

from amazon-product-api.

masterT avatar masterT commented on June 14, 2024

I suggest you to get familiar with the markdown syntaxe. It is very useful since you can use it to write issue and comment.

from amazon-product-api.

Codepoet77 avatar Codepoet77 commented on June 14, 2024

OK thanks for all the info! I think I've managed to submit a PR.

from amazon-product-api.

Codepoet77 avatar Codepoet77 commented on June 14, 2024

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).

from amazon-product-api.

masterT avatar masterT commented on June 14, 2024

Fix in PR #23

from amazon-product-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.