user3465123
user3465123

Reputation: 13

Node Js and Ebay api

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

Upvotes: 1

Views: 3385

Answers (2)

Ajaykumar
Ajaykumar

Reputation: 416

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/

Upvotes: 1

Madhankumar
Madhankumar

Reputation: 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.

Upvotes: 0

Related Questions