Skip to content

Commit 1b53c7e

Browse files
committed
get items by group id
1 parent d0b820c commit 1b53c7e

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
npm-debug.log
2+
npm-debug.log
3+
.vscode/

demo/browseApi.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const Ebay = require('../src/index');
22
let access_token = "";
33
let ebay = new Ebay({
4-
clientID: "--Client ID -----",
4+
clientID: "---Client Id------",
55
clientSecret: '-- Client Secret----',
66
body: {
77
grant_type: "client_credentials",
8-
scope: 'https://api.ebay.com/oauth/api_scope'
8+
scope: 'PRD-f1a91299c206-f184-45e0-b068-f139'
99

1010
}
1111
});
@@ -47,3 +47,18 @@ ebay.getAccessToken()
4747
});
4848
});
4949

50+
51+
//retrieves the details of the individual items in an item group
52+
// reference https://developer.ebay.com/api-docs/buy/browse/resources/item/methods/getItemsByItemGroup#uri.item_group_id
53+
ebay.getAccessToken()
54+
.then((data) => {
55+
ebay.getItemByItemGroup("151915076499").then((data) => {
56+
// Data is in format of JSON
57+
// To check the format of Data, Go to this url (https://jsonblob.com/56cbea67-30b8-11e8-953c-5d1886dcf4a0)
58+
console.log(data)
59+
}, (error) => {
60+
console.log(error);
61+
});
62+
});
63+
64+

src/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ Ebay.prototype = {
125125
});
126126
},
127127

128+
getItemByItemGroup: function (itemGroupId) {
129+
if (typeof itemGroupId == "object") throw new Error("Expecting String or number (Item group id)");
130+
if (!itemGroupId) throw new Error("Error Item Group ID is required");
131+
if (!this.options.access_token) throw new Error("Missing Access token, Generate access token");
132+
const auth = "Bearer " + this.options.access_token;
133+
return new Promise((resolve, reject) => {
134+
makeRequest('api.ebay.com', `/buy/browse/v1/item/get_items_by_item_group?item_group_id=${itemGroupId}`, 'GET', this.options.body, auth).then((result) => {
135+
resolve(JSON.parse(result));
136+
});
137+
})
138+
139+
140+
},
141+
128142
setAccessToken: function (token) {
129143

130144
this.options.access_token = token;
@@ -136,17 +150,14 @@ Ebay.prototype = {
136150
if (!this.options.body) throw new Error("Missing Body, required Grant type");
137151
const encodedStr = base64Encode(this.options.clientID + ":" + this.options.clientSecret);
138152
let self = this;
139-
console.log(this.options.body);
140153
const auth = "Basic " + encodedStr;
141154
return makeRequest('api.ebay.com', '/identity/v1/oauth2/token', 'POST', this.options.body, auth).then((result) => {
142-
console.log("Successssssssss");
143155
let resultJSON = JSON.parse(result);
144-
// console.log(this);
156+
console.log(resultJSON);
145157
self.setAccessToken(resultJSON.access_token);
146158
return resultJSON;
147159
});
148160
}
149-
150161
};
151162

152163
module.exports = Ebay;

0 commit comments

Comments
 (0)