From ffa4bf3c9322c4c5b7514ae032f238fb7b59b106 Mon Sep 17 00:00:00 2001 From: Ajaykumar Date: Sat, 6 Jun 2020 18:39:01 -0700 Subject: [PATCH] Added filtering to findItemsByCategory api (#104) * v2.7.7 * fix encodeURI issue * version bump * added filtering for findItemsByCategory api * version bump * version bump --- README.md | 13 +++++++++++++ demo/finding.js | 5 ++++- package.json | 2 +- src/buildURL.js | 3 +-- src/finding.js | 19 +++++++++---------- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e6f4bea..d207c12 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,19 @@ ebay.getAccessToken() // To check the format of Data, Go to this url (https://developer.ebay.com/api- docs/buy/browse/resources/item_summary/methods/search#w4-w1-w4-SearchforItemsbyKeyword-0) }) }); + +// perform Advance Search Items by Keyword or category or both +// Search Buy It Now ipad items with one day shipping. (https://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html) +ebay.findItemsAdvanced({ + entriesPerPage: 2, + keywords: 'ipad', + ExpeditedShippingType: 'OneDayShipping', + ListingType: 'AuctionWithBIN' +}).then((data) => { + console.log(data); +}, (error) => { + console.log(error); +}); ``` [More Examples](https://pajaydev.github.io/ebay-node-api) diff --git a/demo/finding.js b/demo/finding.js index 4d8817f..f1d975f 100644 --- a/demo/finding.js +++ b/demo/finding.js @@ -7,7 +7,10 @@ let ebay = new Ebay({ clientID: clientId, }); -ebay.findItemsByCategory(10181).then((data) => { +ebay.findItemsByCategory({ + categoryId: 10181, + Condition: 1000 +}).then((data) => { console.log(data); }, (error) => { console.log(error); diff --git a/package.json b/package.json index b1779dd..f407143 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ebay-node-api", - "version": "2.8.6", + "version": "2.8.7", "description": "Ebay node api client", "main": "./src/index.js", "homepage": "https://github.com/pajaydev/ebay-node-api", diff --git a/src/buildURL.js b/src/buildURL.js index 7d424b5..2eb9f8a 100644 --- a/src/buildURL.js +++ b/src/buildURL.js @@ -23,8 +23,7 @@ const buildURL = { baseUrl += options.param ? '&' + options.param + '=' + options.name : ''; baseUrl += options.additionalParam ? '&' + options.additionalParam : ''; baseUrl += options.sortOrder ? '&sortOrder=' + options.sortOrder : ''; - baseUrl += '&outputSelector(0)=SellerInfo'; - baseUrl += '&outputSelector(1)=PictureURLLarge'; + baseUrl += '&outputSelector(0)=SellerInfo&outputSelector(1)=PictureURLLarge'; baseUrl += options.limit ? '&paginationInput.entriesPerPage=' + options.limit : ''; baseUrl += options.globalID ? '&GLOBAL-ID=' + options.globalID : ''; baseUrl += options.pageNumber ? '&paginationInput.pageNumber=' + options.pageNumber : ''; diff --git a/src/finding.js b/src/finding.js index 2c5c85e..46709f6 100644 --- a/src/finding.js +++ b/src/finding.js @@ -10,9 +10,7 @@ const FIND_ITEMS_ADV = 'findItemsAdvanced'; const FIND_EBAY_STORES = 'findItemsIneBayStores'; const findItemsByKeywords = function (options) { - if (!options) { - throw new Error('INVALID_REQUEST_PARMS --> Keyword is missing, Keyword is required'); - } + if (!options) throw new Error('INVALID_REQUEST_PARMS --> Keyword is missing, Keyword is required'); this.options.operationName = FIND_ITEMS_BY_KEYWORD; // support only keyword string. if (!options.keywords) options = { keywords: options }; @@ -24,11 +22,15 @@ const findItemsByKeywords = function (options) { ); }; -const findItemsByCategory = function (categoryID) { - if (!categoryID) throw new Error('INVALID_REQUEST_PARMS --> Category ID is null or invalid'); - this.options.name = categoryID; +/** + * searches for items on eBay using specific eBay category ID numbers (input category ID numbers using categoryId). + * @param {Object} options + */ +const findItemsByCategory = function (options) { + if (!options) throw new Error('INVALID_REQUEST_PARMS --> Category ID is null or invalid'); + if (!options.categoryId) options = { categoryId: options }; this.options.operationName = FIND_ITEMS_BY_CATEGORY; - this.options.param = 'categoryId'; + this.options.additionalParam = utils.constructAdditionalParams(options); const url = urlObject.buildSearchUrl(this.options); return getRequest(url).then((data) => { return JSON.parse(data).findItemsByCategoryResponse; @@ -49,7 +51,6 @@ const findCompletedItems = function (options) { const url = urlObject.buildSearchUrl(this.options); return getRequest(url).then((data) => { return JSON.parse(data).findCompletedItemsResponse; - }, console.error // eslint-disable-line no-console ); }; @@ -94,7 +95,6 @@ const findItemsByProduct = function (options) { let url = `${urlObject.buildSearchUrl(this.options)}&productId.@type=${type}`; return getRequest(url).then((data) => { return JSON.parse(data).findItemsByProductResponse; - }, console.error // eslint-disable-line no-console ); }; @@ -106,7 +106,6 @@ const findItemsIneBayStores = function (options) { this.options.additionalParam = utils.constructAdditionalParams(options); return getRequest(urlObject.buildSearchUrl(this.options)).then((data) => { return JSON.parse(data).findItemsIneBayStoresResponse; - }, console.error // eslint-disable-line no-console ); };