Skip to content

Commit 31fdf38

Browse files
committed
adding extra params to findItemsByKeyword
1 parent c8f5eac commit 31fdf38

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

demo/findingApi.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ ebay.findItemsByCategory(10181).then((data) => {
1111
console.log(error);
1212
});
1313

14-
ebay.findItemsByKeywords('iphone').then((data) => {
14+
// refer here for filtering the items
15+
// https://developer.ebay.com/devzone/finding/callref/finditemsbykeywords.html#control
16+
ebay.findItemsByKeywords({
17+
keywords: 'iphone',
18+
sortOrder: 'PricePlusShippingLowest', //https://developer.ebay.com/devzone/finding/callref/extra/fndcmpltditms.rqst.srtordr.html
19+
Condition: 3000,
20+
SoldItemsOnly: false
21+
}).then((data) => {
1522
console.log(data);
1623
}, (error) => {
1724
console.log(error);
1825
});
1926

2027
//https://developer.ebay.com/devzone/finding/callref/findCompletedItems.html
21-
/* This call searches for items whose listings are completed and are no longer available for
22-
sale by category (using categoryId), by keywords (using keywords), or a combination of the two.
28+
/* This call searches for items whose listings are completed and are no longer available for
29+
sale by category (using categoryId), by keywords (using keywords), or a combination of the two.
2330
Keyword queries search the title and subtitle of the item; they do not search descriptions. */
2431

2532
ebay.findCompletedItems({

demo/searchApi.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let ebay = new Ebay({
1313
});
1414

1515

16-
// //Search for Items by Keyword.
16+
// // //Search for Items by Keyword.
1717
ebay.getAccessToken()
1818
.then((data) => {
1919
ebay.searchItems({
@@ -63,7 +63,8 @@ ebay.getAccessToken()
6363
ebay.searchItems({
6464
keyword: 'drone',
6565
limit: 3,
66-
filter: { maxDeliveryCost: 0 }
66+
filter: { maxDeliveryCost: 0 },
67+
aspect_filter: { categoryId: 179697, conditionDistributions: '{NEW}' } // docs to provide aspect_filter https://developer.ebay.com/api-docs/buy/browse/resources/item_summary/methods/search#h2-input
6768
}).then((data) => {
6869
console.log(data);
6970
// Data is in format of JSON

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ebay-node-api",
3-
"version": "2.7.2",
3+
"version": "2.7.4",
44
"description": "Ebay node api client",
55
"main": "./src/index.js",
66
"homepage": "https://github.com/pajaydev/ebay-node-api",
@@ -40,4 +40,4 @@
4040
"nock": "^9.2.3",
4141
"sinon": "^4.4.5"
4242
}
43-
}
43+
}

src/buy-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const searchItems = function (searchConfig) {
6060
queryParam = queryParam + (searchConfig.sort ? '&sort=' + searchConfig.sort : '');
6161
if (searchConfig.fieldgroups !== undefined) queryParam = queryParam + '&fieldgroups=' + searchConfig.fieldgroups;
6262
if (searchConfig.filter !== undefined) queryParam = queryParam + '&filter=' + encodeURLQuery(makeString(searchConfig.filter, { quotes: 'no', braces: 'false' }));
63-
queryParam = queryParam + (searchConfig.aspect_filter ? '&aspect_filter='+ encodeURLQuery(makeString(searchConfig.aspect_filter, { quotes: 'no', braces: 'false' })) : '');
63+
queryParam = queryParam + (searchConfig.aspect_filter ? '&aspect_filter=' + encodeURLQuery(makeString(searchConfig.aspect_filter, { quotes: 'no', braces: 'false' })) : '');
6464
this.options.contentType = 'application/json';
6565
return new Promise((resolve, reject) => {
6666
makeRequest(this.options, `/buy/browse/v1/item_summary/search?${(queryParam)}`, 'GET', auth).then((result) => {

src/findingApi.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@ const { getRequest } = require('./request');
55

66
const findItemsByKeywords = function (options) {
77
if (!options) {
8-
throw new Error('Keyword is missing, Keyword is required');
8+
throw new Error('INVALID_REQUEST_PARMS --> Keyword is missing, Keyword is required');
99
}
1010
this.options.operationName = 'findItemsByKeywords';
1111
this.options.param = 'keywords';
1212
// support only keyword string.
1313
if (!options.keywords) {
1414
this.options.name = options;
1515
}
16-
else {
17-
this.options.name = encodeURIComponent(options.keywords);
18-
this.options.sortOrder = options.sortOrder;
19-
this.options.pageNumber = options.pageNumber;
20-
this.options.limit = options.limit;
21-
}
22-
16+
this.options.additionalParam = constructAdditionalParams(options);
2317
const url = urlObject.buildSearchUrl(this.options);
2418
return getRequest(url).then((data) => {
2519
return JSON.parse(data).findItemsByKeywordsResponse;
@@ -29,7 +23,7 @@ const findItemsByKeywords = function (options) {
2923
};
3024

3125
const findItemsByCategory = function (categoryID) {
32-
if (!categoryID) throw new Error('Category ID is null or invalid');
26+
if (!categoryID) throw new Error('INVALID_REQUEST_PARMS --> Category ID is null or invalid');
3327
this.options.name = categoryID;
3428
this.options.operationName = 'findItemsByCategory';
3529
this.options.param = 'categoryId';
@@ -47,7 +41,7 @@ const findItemsByCategory = function (categoryID) {
4741
* @param {Object} options
4842
*/
4943
const findCompletedItems = function (options) {
50-
if (!options) throw new Error('Keyword or category ID are required.');
44+
if (!options) throw new Error('INVALID_REQUEST_PARMS --> Keyword or category ID are required.');
5145
if (!options.keywords && !options.categoryId) throw new Error('Keyword or category ID are required.');
5246
if (options.keywords) {
5347
options.keywords = encodeURIComponent(options.keywords);
@@ -77,8 +71,8 @@ const getVersion = function () {
7771
* @param {Object} options
7872
*/
7973
const findItemsByProduct = function (options) {
80-
if (!options) throw new Error('Please enter the Valid input.');
81-
if (!options.productId) throw new Error('Product ID is required.');
74+
if (!options) throw new Error('INVALID_REQUEST_PARMS --> Please enter the Valid input.');
75+
if (!options.productId) throw new Error('INVALID_REQUEST_PARMS --> Product ID is required.');
8276
this.options.operationName = 'findItemsByProduct';
8377
this.options.additionalParam = constructAdditionalParams(options);
8478
let url = urlObject.buildSearchUrl(this.options);
@@ -90,6 +84,12 @@ const findItemsByProduct = function (options) {
9084
);
9185
};
9286

87+
88+
/**
89+
* Constructs query param based on some logic to support filter and aspect_filter params.
90+
* output will be keywords=iphone&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=FreeShippingOnly&itemFilter(1).value=true&itemFilter(2).name=SoldItemsOnly&itemFilter(2).value=true
91+
* @param {Object} options
92+
*/
9393
const constructAdditionalParams = (options) => {
9494
let params = '';
9595
let count = 0;

0 commit comments

Comments
 (0)