1
votes

I am novice to NodeJs and working with ebay-api. I found this great example at GitHub

one strange issue is when I run the js file via CMD. it is working but sometimes it shows error and then I cleared cache it works and sometimes after clearing the cache it shows error. But the code is exactly the same which I got output correctly. Did anyone face the same issue or any idea where might be the problem?

var ebay = require('../index.js');

var params = {
keywords: ["Canon", "Powershot"],

// add additional fields
outputSelector: ['AspectHistogram'],

paginationInput: {
entriesPerPage: 10
},

itemFilter: [
{name: 'FreeShippingOnly', value: true},
{name: 'MaxPrice', value: '150'}
],

domainFilter: [
{name: 'domainName', value: 'Digital_Cameras'}
]
};

ebay.xmlRequest({
serviceName: 'Finding',
opType: 'findItemsByKeywords',
appId: '<your app id>', // FILL IN YOUR OWN APP KEY
params: params,
parser: ebay.parseResponseJson // (default)
},

// gets all the items together in a merged array

function itemsCallback(error, itemsResponse) {
if (error) throw error;

var items = itemsResponse.searchResult.item;

console.log('Found', items.length, 'items');

for (var i = 0; i < items.length; i++) {
console.log('- ' + items[i].title);
console.log('- ' + items[i].galleryURL);
console.log('- ' + items[i].viewItemURL);
} 
}
);

I'm getting the following errors:

C:\node_modules\ebay-api\examples> node H:\NodeJs\app.js //Run via NodeJS CMD

H:\NodeJs\app.js:36 if (error) throw error; ^ Error at Request._callback (C:\Users\shiva raju\node_modules\ebay-api\lib\xml-request.js:151:23) at Request.self.callback (C:\Users\shiva raju\node_modules\ebay-api\node_modules\request\request.js:200:22) at emitTwo (events.js:106:13) at Request.emit (events.js:194:7) at Request. (C:\Users\shiva raju\node_modules\ebay-api\node_modules\request\request.js:1067:10) at emitOne (events.js:101:20) at Request.emit (events.js:191:7) at IncomingMessage. (C:\Users\shiva raju\node_modules\ebay-api\node_modules\request\request.js:988:12) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:188:7)

Your suggestions would be appreciated. Thanks

2
An environment is configured correctly. I can able to run other nodejs files. This file too runs for the first time. when i make a change and if i run it again it shows error and when i undo the change and run the old code still it shows error. :(user3465123
https://github.com/bhushankumarl/eBay-node-client/tree/master/examples/javaScript Here are a lot of example with working javascript available. Novice developer can easily update it. Try this instead if you still looking for same.Bhushankumar Lilapara

2 Answers

1
votes

You can use this node module ebay-node-api where you can get the response data in form of JSON.

You can check this example to check how to consume ebay-node-api https://github.com/pajaydev/ebay-node-api/

0
votes

You are throwing an error object in the callback but you are not catching it anywhere in the code. Please handle the error you are throwing.