skip to Main Content

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_modulesebay-apiexamples> node H:NodeJsapp.js //Run via NodeJS CMD

H:NodeJsapp.js:36
if (error) throw error;
^
Error
at Request._callback (C:Usersshiva rajunode_modulesebay-apilibxml-request.js:151:23)
at Request.self.callback (C:Usersshiva rajunode_modulesebay-apinode_modulesrequestrequest.js:200:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:194:7)
at Request. (C:Usersshiva rajunode_modulesebay-apinode_modulesrequestrequest.js:1067:10)
at emitOne (events.js:101:20)
at Request.emit (events.js:191:7)
at IncomingMessage. (C:Usersshiva rajunode_modulesebay-apinode_modulesrequestrequest.js:988:12)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)

Your suggestions would be appreciated. Thanks

2

Answers


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

    Login or Signup to reply.
  2. 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/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search