Skip to content

Commit 83b88be

Browse files
committed
added findItemsByProduct support
1 parent dd84153 commit 83b88be

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

demo/findingApi.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ ebay.findCompletedItems({
3535
console.log(error);
3636
});
3737

38+
// This call searches for items on eBay using specific eBay product values.
39+
// https://developer.ebay.com/DevZone/finding/CallRef/findItemsByProduct.html#findItemsByProduct
40+
ebay.findItemsByProduct({
41+
productId: 53039031,
42+
entriesPerPage: 2
43+
}).then((data) => {
44+
console.log(data);
45+
}, (error) => {
46+
console.log(error);
47+
});
48+
3849
ebay.getVersion().then((data) => {
3950
console.log(data.version);
4051
}, (error) => {

src/findingApi.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ const urlObject = require('./buildURL');
44
const { getRequest } = require('./request');
55

66
const findItemsByKeywords = function (options) {
7-
if (!options || !options.keywords) {
7+
if (!options) {
88
throw new Error('Keyword is missing, Keyword is required');
99
}
10-
1110
this.options.operationName = 'findItemsByKeywords';
1211
this.options.param = 'keywords';
13-
12+
// support only keyword string.
1413
if (!options.keywords) {
1514
this.options.name = options;
1615
}
@@ -42,6 +41,11 @@ const findItemsByCategory = function (categoryID) {
4241
);
4342
};
4443

44+
/**
45+
* searches for items whose listings are completed and are no longer available for
46+
* sale by category (using categoryId), by keywords (using keywords), or a combination of the two.
47+
* @param {Object} options
48+
*/
4549
const findCompletedItems = function (options) {
4650
if (!options) throw new Error('Keyword or category ID are required.');
4751
if (!options.keywords && !options.categoryId) throw new Error('Keyword or category ID are required.');
@@ -58,6 +62,7 @@ const findCompletedItems = function (options) {
5862
);
5963
};
6064

65+
6166
const getVersion = function () {
6267
this.options.operationName = 'getVersion';
6368
const url = urlObject.buildSearchUrl(this.options);
@@ -67,6 +72,24 @@ const getVersion = function () {
6772
);
6873
};
6974

75+
/**
76+
* Searches for items on eBay using specific eBay product values.
77+
* @param {Object} options
78+
*/
79+
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.');
82+
this.options.operationName = 'findItemsByProduct';
83+
this.options.additionalParam = constructAdditionalParams(options);
84+
let url = urlObject.buildSearchUrl(this.options);
85+
url = `${url}&productId.@type=ReferenceID`;
86+
return getRequest(url).then((data) => {
87+
return JSON.parse(data).findItemsByProductResponse;
88+
89+
}, console.error
90+
);
91+
};
92+
7093
const constructAdditionalParams = (options) => {
7194
let params = '';
7295
let count = 0;
@@ -75,7 +98,7 @@ const constructAdditionalParams = (options) => {
7598
if (key === 'entriesPerPage' || key === 'pageNumber') {
7699
params = `${params}paginationInput.${key}=${options[key]}&`;
77100
}
78-
else if (key === 'keywords' || key === 'categoryId' || key === 'sortOrder') {
101+
else if (key === 'keywords' || key === 'categoryId' || key === 'productId' || key === 'sortOrder') {
79102
params = `${params}${key}=${options[key]}&`;
80103
}
81104
else {
@@ -95,5 +118,6 @@ module.exports = {
95118
findItemsByCategory,
96119
findCompletedItems,
97120
constructAdditionalParams,
121+
findItemsByProduct,
98122
getVersion
99123
};

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const { getDefaultCategoryTreeId,
1515
const { findItemsByKeywords,
1616
findItemsByCategory,
1717
findCompletedItems,
18+
findItemsByProduct,
1819
getVersion } = require('./findingApi');
1920
const { setAccessToken,
2021
getAccessToken,
@@ -63,6 +64,7 @@ Ebay.prototype = {
6364
findItemsByKeywords,
6465
findItemsByCategory,
6566
findCompletedItems,
67+
findItemsByProduct,
6668
getVersion,
6769
getItem,
6870
getItemByLegacyId,

0 commit comments

Comments
 (0)