ebay-api 1.13.7 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/LICENSE +18 -19
  2. package/README.md +512 -118
  3. package/lib/api/apiFactory.d.ts +27 -0
  4. package/lib/api/apiFactory.js +100 -0
  5. package/lib/api/apiFactory.js.map +1 -0
  6. package/lib/api/base.d.ts +13 -0
  7. package/lib/api/base.js +25 -0
  8. package/lib/api/base.js.map +1 -0
  9. package/lib/api/index.d.ts +11 -0
  10. package/lib/api/index.js +18 -0
  11. package/lib/api/index.js.map +1 -0
  12. package/lib/api/restful/buy/browse/index.d.ts +84 -0
  13. package/lib/api/restful/buy/browse/index.js +142 -0
  14. package/lib/api/restful/buy/browse/index.js.map +1 -0
  15. package/lib/api/restful/buy/deal/index.d.ts +55 -0
  16. package/lib/api/restful/buy/deal/index.js +80 -0
  17. package/lib/api/restful/buy/deal/index.js.map +1 -0
  18. package/lib/api/restful/buy/feed/index.d.ts +43 -0
  19. package/lib/api/restful/buy/feed/index.js +85 -0
  20. package/lib/api/restful/buy/feed/index.js.map +1 -0
  21. package/lib/api/restful/buy/index.d.ts +17 -0
  22. package/lib/api/restful/buy/index.js +21 -0
  23. package/lib/api/restful/buy/index.js.map +1 -0
  24. package/lib/api/restful/buy/marketing/index.d.ts +27 -0
  25. package/lib/api/restful/buy/marketing/index.js +51 -0
  26. package/lib/api/restful/buy/marketing/index.js.map +1 -0
  27. package/lib/api/restful/buy/marketplaceInsights/index.d.ts +28 -0
  28. package/lib/api/restful/buy/marketplaceInsights/index.js +51 -0
  29. package/lib/api/restful/buy/marketplaceInsights/index.js.map +1 -0
  30. package/lib/api/restful/buy/offer/index.d.ts +23 -0
  31. package/lib/api/restful/buy/offer/index.js +37 -0
  32. package/lib/api/restful/buy/offer/index.js.map +1 -0
  33. package/lib/api/restful/buy/order/index.d.ts +264 -0
  34. package/lib/api/restful/buy/order/index.js +369 -0
  35. package/lib/api/restful/buy/order/index.js.map +1 -0
  36. package/lib/api/restful/commerce/catalog/index.d.ts +73 -0
  37. package/lib/api/restful/commerce/catalog/index.js +108 -0
  38. package/lib/api/restful/commerce/catalog/index.js.map +1 -0
  39. package/lib/api/restful/commerce/charity/index.d.ts +34 -0
  40. package/lib/api/restful/commerce/charity/index.js +56 -0
  41. package/lib/api/restful/commerce/charity/index.js.map +1 -0
  42. package/lib/api/restful/commerce/identity/index.d.ts +14 -0
  43. package/lib/api/restful/commerce/identity/index.js +27 -0
  44. package/lib/api/restful/commerce/identity/index.js.map +1 -0
  45. package/lib/api/restful/commerce/index.d.ts +15 -0
  46. package/lib/api/restful/commerce/index.js +19 -0
  47. package/lib/api/restful/commerce/index.js.map +1 -0
  48. package/lib/api/restful/commerce/notification/index.d.ts +117 -0
  49. package/lib/api/restful/commerce/notification/index.js +187 -0
  50. package/lib/api/restful/commerce/notification/index.js.map +1 -0
  51. package/lib/api/restful/commerce/taxonomy/index.d.ts +78 -0
  52. package/lib/api/restful/commerce/taxonomy/index.js +135 -0
  53. package/lib/api/restful/commerce/taxonomy/index.js.map +1 -0
  54. package/lib/api/restful/commerce/translation/index.d.ts +15 -0
  55. package/lib/api/restful/commerce/translation/index.js +25 -0
  56. package/lib/api/restful/commerce/translation/index.js.map +1 -0
  57. package/lib/api/restful/developer/analytics/index.d.ts +22 -0
  58. package/lib/api/restful/developer/analytics/index.js +45 -0
  59. package/lib/api/restful/developer/analytics/index.js.map +1 -0
  60. package/lib/api/restful/developer/index.d.ts +5 -0
  61. package/lib/api/restful/developer/index.js +9 -0
  62. package/lib/api/restful/developer/index.js.map +1 -0
  63. package/lib/api/restful/index.d.ts +63 -0
  64. package/lib/api/restful/index.js +165 -0
  65. package/lib/api/restful/index.js.map +1 -0
  66. package/lib/api/restful/postOrder/cancellation/index.d.ts +57 -0
  67. package/lib/api/restful/postOrder/cancellation/index.js +95 -0
  68. package/lib/api/restful/postOrder/cancellation/index.js.map +1 -0
  69. package/lib/api/restful/postOrder/case/index.d.ts +63 -0
  70. package/lib/api/restful/postOrder/case/index.js +97 -0
  71. package/lib/api/restful/postOrder/case/index.js.map +1 -0
  72. package/lib/api/restful/postOrder/index.d.ts +11 -0
  73. package/lib/api/restful/postOrder/index.js +15 -0
  74. package/lib/api/restful/postOrder/index.js.map +1 -0
  75. package/lib/api/restful/postOrder/inquiry/index.d.ts +82 -0
  76. package/lib/api/restful/postOrder/inquiry/index.js +131 -0
  77. package/lib/api/restful/postOrder/inquiry/index.js.map +1 -0
  78. package/lib/api/restful/postOrder/return/index.d.ts +231 -0
  79. package/lib/api/restful/postOrder/return/index.js +361 -0
  80. package/lib/api/restful/postOrder/return/index.js.map +1 -0
  81. package/lib/api/restful/sell/account/index.d.ts +217 -0
  82. package/lib/api/restful/sell/account/index.js +337 -0
  83. package/lib/api/restful/sell/account/index.js.map +1 -0
  84. package/lib/api/restful/sell/analytics/index.d.ts +41 -0
  85. package/lib/api/restful/sell/analytics/index.js +61 -0
  86. package/lib/api/restful/sell/analytics/index.js.map +1 -0
  87. package/lib/api/restful/sell/compliance/index.d.ts +37 -0
  88. package/lib/api/restful/sell/compliance/index.js +57 -0
  89. package/lib/api/restful/sell/compliance/index.js.map +1 -0
  90. package/lib/api/restful/sell/feed/index.d.ts +151 -0
  91. package/lib/api/restful/sell/feed/index.js +255 -0
  92. package/lib/api/restful/sell/feed/index.js.map +1 -0
  93. package/lib/api/restful/sell/finances/index.d.ts +74 -0
  94. package/lib/api/restful/sell/finances/index.js +105 -0
  95. package/lib/api/restful/sell/finances/index.js.map +1 -0
  96. package/lib/api/restful/sell/fulfillment/index.d.ts +137 -0
  97. package/lib/api/restful/sell/fulfillment/index.js +199 -0
  98. package/lib/api/restful/sell/fulfillment/index.js.map +1 -0
  99. package/lib/api/restful/sell/index.d.ts +29 -0
  100. package/lib/api/restful/sell/index.js +33 -0
  101. package/lib/api/restful/sell/index.js.map +1 -0
  102. package/lib/api/restful/sell/inventory/index.d.ts +248 -0
  103. package/lib/api/restful/sell/inventory/index.js +346 -0
  104. package/lib/api/restful/sell/inventory/index.js.map +1 -0
  105. package/lib/api/restful/sell/listing/index.d.ts +14 -0
  106. package/lib/api/restful/sell/listing/index.js +25 -0
  107. package/lib/api/restful/sell/listing/index.js.map +1 -0
  108. package/lib/api/restful/sell/logistics/index.d.ts +44 -0
  109. package/lib/api/restful/sell/logistics/index.js +66 -0
  110. package/lib/api/restful/sell/logistics/index.js.map +1 -0
  111. package/lib/api/restful/sell/marketing/index.d.ts +443 -0
  112. package/lib/api/restful/sell/marketing/index.js +609 -0
  113. package/lib/api/restful/sell/marketing/index.js.map +1 -0
  114. package/lib/api/restful/sell/metadata/index.d.ts +77 -0
  115. package/lib/api/restful/sell/metadata/index.js +131 -0
  116. package/lib/api/restful/sell/metadata/index.js.map +1 -0
  117. package/lib/api/restful/sell/negotiation/index.d.ts +24 -0
  118. package/lib/api/restful/sell/negotiation/index.js +39 -0
  119. package/lib/api/restful/sell/negotiation/index.js.map +1 -0
  120. package/lib/api/restful/sell/recommendation/index.d.ts +26 -0
  121. package/lib/api/restful/sell/recommendation/index.js +39 -0
  122. package/lib/api/restful/sell/recommendation/index.js.map +1 -0
  123. package/lib/api/traditional/XMLRequest.d.ts +98 -0
  124. package/lib/api/traditional/XMLRequest.js +191 -0
  125. package/lib/api/traditional/XMLRequest.js.map +1 -0
  126. package/lib/api/traditional/clientAlerts/index.d.ts +9 -0
  127. package/lib/api/traditional/clientAlerts/index.js +15 -0
  128. package/lib/api/traditional/clientAlerts/index.js.map +1 -0
  129. package/lib/api/traditional/clientAlerts/types.d.ts +31 -0
  130. package/lib/api/traditional/clientAlerts/types.js +36 -0
  131. package/lib/api/traditional/clientAlerts/types.js.map +1 -0
  132. package/lib/api/traditional/fields.d.ts +1948 -0
  133. package/lib/api/traditional/fields.js +1949 -0
  134. package/lib/api/traditional/fields.js.map +1 -0
  135. package/lib/api/traditional/finding/index.d.ts +12 -0
  136. package/lib/api/traditional/finding/index.js +16 -0
  137. package/lib/api/traditional/finding/index.js.map +1 -0
  138. package/lib/api/traditional/index.d.ts +17 -0
  139. package/lib/api/traditional/index.js +207 -0
  140. package/lib/api/traditional/index.js.map +1 -0
  141. package/lib/api/traditional/merchandising/index.d.ts +7 -0
  142. package/lib/api/traditional/merchandising/index.js +11 -0
  143. package/lib/api/traditional/merchandising/index.js.map +1 -0
  144. package/lib/api/traditional/shopping/index.d.ts +11 -0
  145. package/lib/api/traditional/shopping/index.js +16 -0
  146. package/lib/api/traditional/shopping/index.js.map +1 -0
  147. package/lib/api/traditional/trading/index.d.ts +142 -0
  148. package/lib/api/traditional/trading/index.js +146 -0
  149. package/lib/api/traditional/trading/index.js.map +1 -0
  150. package/lib/auth/authNAuth.d.ts +49 -0
  151. package/lib/auth/authNAuth.js +122 -0
  152. package/lib/auth/authNAuth.js.map +1 -0
  153. package/lib/auth/index.d.ts +17 -0
  154. package/lib/auth/index.js +32 -0
  155. package/lib/auth/index.js.map +1 -0
  156. package/lib/auth/oAuth2.d.ts +90 -0
  157. package/lib/auth/oAuth2.js +258 -0
  158. package/lib/auth/oAuth2.js.map +1 -0
  159. package/lib/ebay-api.min.js +2 -0
  160. package/lib/ebay-api.min.js.map +1 -0
  161. package/lib/enums/apiEnums.d.ts +49 -0
  162. package/lib/enums/apiEnums.js +55 -0
  163. package/lib/enums/apiEnums.js.map +1 -0
  164. package/lib/enums/index.d.ts +2 -0
  165. package/lib/enums/index.js +15 -0
  166. package/lib/enums/index.js.map +1 -0
  167. package/lib/enums/restfulEnums.d.ts +966 -0
  168. package/lib/enums/restfulEnums.js +1012 -0
  169. package/lib/enums/restfulEnums.js.map +1 -0
  170. package/lib/errors/index.d.ts +66 -0
  171. package/lib/errors/index.js +208 -0
  172. package/lib/errors/index.js.map +1 -0
  173. package/lib/index.d.ts +56 -0
  174. package/lib/index.js +99 -0
  175. package/lib/index.js.map +1 -0
  176. package/lib/request.d.ts +26 -0
  177. package/lib/request.js +51 -0
  178. package/lib/request.js.map +1 -0
  179. package/lib/types/apiTypes.d.ts +28 -0
  180. package/lib/types/apiTypes.js +3 -0
  181. package/lib/types/apiTypes.js.map +1 -0
  182. package/lib/types/index.d.ts +3 -0
  183. package/lib/types/index.js +16 -0
  184. package/lib/types/index.js.map +1 -0
  185. package/lib/types/restfulTypes.d.ts +1082 -0
  186. package/lib/types/restfulTypes.js +3 -0
  187. package/lib/types/restfulTypes.js.map +1 -0
  188. package/lib/types/traditonalTypes.d.ts +34 -0
  189. package/lib/types/traditonalTypes.js +3 -0
  190. package/lib/types/traditonalTypes.js.map +1 -0
  191. package/package.json +115 -21
  192. package/.npmignore +0 -17
  193. package/.travis.yml +0 -7
  194. package/examples/Finding-FindItemsByKeywords.js +0 -46
  195. package/examples/Merchandising-GetMostWatchedItemsRequest.js +0 -16
  196. package/examples/Shopping-GetSingleItem.js +0 -18
  197. package/examples/Trading-GetOrders.js +0 -26
  198. package/index.js +0 -10
  199. package/lib/deep-to-array.js +0 -42
  200. package/lib/defaults.js +0 -69
  201. package/lib/errors.js +0 -44
  202. package/lib/json-parser.js +0 -336
  203. package/lib/key-lists.js +0 -64
  204. package/lib/urls.js +0 -64
  205. package/lib/versions.js +0 -35
  206. package/lib/xml-converter.js +0 -21
  207. package/lib/xml-request.js +0 -207
  208. package/scripts/parse-input-xml.js +0 -41
  209. package/test/deep-to-array.test.js +0 -100
  210. package/test/errors.test.js +0 -75
  211. package/test/helpers.js +0 -22
  212. package/test/mocha.opts +0 -1
  213. package/test/mocks/GetMultipleItems.xml +0 -115
  214. package/test/mocks/GetOrders-empty.xml +0 -17
  215. package/test/mocks/GetOrders.xml +0 -463
  216. package/test/pagination.test.js +0 -5
  217. package/test/parsing.test.js +0 -248
  218. package/test/xml-request.test.js +0 -447
package/README.md CHANGED
@@ -1,149 +1,543 @@
1
- eBay API client for Node.js
2
- ===============
1
+ # eBay Node API in TypeScript with Browser support
2
+ [![Build Status](https://travis-ci.com/hendt/ebay-api.svg?branch=master)](https://travis-ci.com/hendt/ebay-api)
3
+ [![codecov](https://codecov.io/gh/hendt/ebay-api/branch/master/graph/badge.svg?token=E67PSWIZFZ)](https://codecov.io/gh/hendt/ebay-api)
3
4
 
4
- [![Build Status](https://travis-ci.org/benbuckman/nodejs-ebay-api.svg)](https://travis-ci.org/benbuckman/nodejs-ebay-api)
5
+ This eBay API implements both Traditional \(xml\) and the RESTful eBay API.
6
+ It supports `client credentials grant` and `authorization code grant` \(Auth'N'Auth, OAuth2 and IAF\).
5
7
 
6
- **[Roberto Oliveros](https://www.linkedin.com/in/roberto-oliveros-99467661/) is an eBay API Ninja (as well as an expert at pretty much everything else) and will be the one making the major commits to this module going forwards. Get in touch via the link, he'll be happy to hear from you :)**
8
+ * [API Browser Examples](https://hendt.github.io/ebay-api/)
9
+ * [API Documentation](https://hendt.gitbook.io/ebay-api/)
7
10
 
8
- **A huge thank you to Ben Buckman who performed a huge amount of work on this module. Without his efforts this package wouldn't exist. [Several other people][network] have contributed to the module**
11
+ ## eBay Docs
12
+ * [eBay API Explorer](https://developer.ebay.com/my/api_test_tool)
13
+ * [eBay API Docs](https://developer.ebay.com/docs)
9
14
 
15
+ ## Changelog
10
16
 
11
- ## Intro
17
+ * `v6.2.0` is the latest release.
18
+ * See [here](https://github.com/hendt/ebay-api/blob/master/CHANGELOG.md) for the full changelog.
12
19
 
13
- This module aims to support all of eBay's old APIs (Trading, Shopping, Finding, Merchandising, etc),
14
- with an interface that is both a) somewhat consistent across APIs and b) not too different from the underlying interface.
20
+ ## Implementation status
15
21
 
16
- The old eBay APIs are primarily XML-based, so this module unfortunately has to do a lot of JSON<->XML conversion.
22
+ ### RESTful API
17
23
 
18
- **In due course the repo will be updated and given a new home and we'll start work on some of the issues / pull requests. Please do get in touch if you're working on something and your need is urgent!**
24
+ | API | Implemented |
25
+ | :--- | :--- |
26
+ | **Buy API** | ✔ Browse API `v1.10.0`<br>✔ Deal API `v1.3.0`<br>✔ Feed API<br>✔ Marketing API<br>✔ Offer API<br>✔ Order API<br>✔ Marketplace Insights API |
27
+ | **Commerce API** | ✔ Catalog API<br>✔ Charity API `v1.2.0`<br>✔ Identity API<br>✔ Notification API `v1.2.0`<br>✔ Taxonomy API `v1.0.0`<br>✔ Translation API `v1_beta.1.4` |
28
+ | **Developer API** | ✔ Analytics API|
29
+ | **Post Order API** | ✔ Cancellation API<br>✔ Case Management API<br>✔ Inquiry API<br>✔ Return API |
30
+ | **Sell API** | ✔ Account API `v1.6.3`<br>✔ Analytics API `v1.3.0`<br>✔ Compliance API `v1.4.1`<br>✔ Feed API<br>✔ Finance API `v1.9.0`<br>✔ Fulfillment API `v1.19.10`<br>✔ Inventory API `v1.14.0`<br>✔ Listing API<br>✔ Logistics API<br>✔ Marketing API `v1.10.0`<br>✔ Metadata API<br>✔ Negotiation API `v1.1.0`<br>✔ Recommendation API `v1.1.0`|
19
31
 
32
+ ### Traditional API
20
33
 
21
- ### Current state
34
+ | API | Implemented |
35
+ | :--- | :--- |
36
+ | **Finding API** | ✔ |
37
+ | **Shopping API** | ✔ |
38
+ | **Merchandising API** | ✔ |
39
+ | **Trading API** | ✔ |
40
+ | **Client Alerts API** | ✔ |
41
+ | **Feedback API** | ✔ |
22
42
 
23
- The 1.x branch is currently under active development, and there may be breaking changes between minor releases.
24
- (I realize this is contrary to best practice, but the module is not yet settled enough to major-bump every time.)
43
+ ## Install
25
44
 
26
- **If you are using the 1.x branch, I recommend that you a) let me know your use case, b) help develop it,
27
- c) watch the commit and release logs carefully.**
45
+ ```bash
46
+ npm install ebay-api
47
+ yarn add ebay-api
48
+ ```
28
49
 
50
+ ## 🚀 Usage & Quick start
29
51
 
30
- ## Usage
52
+ Sign up for an API key here: [Developer Account](https://developer.ebay.com/signin?tab=register).
53
+ Checkout API [examples](https://github.com/hendt/ebay-api/tree/master/examples).
31
54
 
32
- `npm install ebay-api`
55
+ ### NodeJS
33
56
 
34
- `var ebay = require('ebay-api');`
57
+ ```javascript
58
+ import eBayApi from 'ebay-api';
59
+ // or:
60
+ // const eBayApi = require('ebay-api')
35
61
 
36
- (See the [examples][examples])
62
+ const eBay = new eBayApi({
63
+ appId: '-- also called Client ID --',
64
+ certId: '-- also called Client Secret --',
65
+ sandbox: false
66
+ });
37
67
 
68
+ const item = await eBay.buy.browse.getItem('v1|254188828753|0');
69
+ console.log(JSON.stringify(item, null, 2));
70
+ ```
38
71
 
39
- ## A eBay APIs
72
+ #### Detailed configuration example
73
+ ```javascript
74
+ import eBayApi from 'ebay-api';
40
75
 
41
- [http://developer.ebay.com](http://developer.ebay.com)
42
-
43
- Sign up for an API key here: [https://publisher.ebaypartnernetwork.com/PublisherToolsAPI](https://publisher.ebaypartnernetwork.com/PublisherToolsAPI)
44
-
45
- (You'll need a key to run the examples.)
46
-
47
- And please make sure to follow the liscence terms: eBay API [License](http://developer.ebay.com/join/licenses/individual/) and [Terms](https://www.x.com/developers/ebay/programs/affiliates/terms) when using this library.
76
+ const eBay = new eBayApi({
77
+ appId: '-- also called Client ID --',
78
+ certId: '-- also called Client Secret --',
79
+ sandbox: false,
48
80
 
81
+ siteId: eBayApi.SiteId.EBAY_US, // required for traditional APIs, see https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html
82
+
83
+ marketplaceId: eBayApi.MarketplaceId.EBAY_US, // defautl. required for RESTful APIs
84
+ acceptLanguage: eBayApi.Locale.en_US, // defautl
85
+ contentLanguage: eBayApi.ContentLanguage.en_US, // defautl.
49
86
 
50
- ## Methods
87
+ // optional parameters, should be omitted if not used
88
+ devId: '-- devId --', // required for traditional Trading API
89
+ ruName: '-- eBay Redirect URL name --', // 'RuName' (eBay Redirect URL name) required for authorization code grant
90
+
91
+ authToken: '-- Auth\'n\'Auth for traditional API (used by trading) --', // can be set to use traditional API without code grant
92
+ });
93
+ ```
94
+
95
+ ### Browser
96
+ Check out live example: [https://hendt.github.io/ebay-api/](https://hendt.github.io/ebay-api/).
97
+ Because of the eBay CORS problems a Proxy server is required to use the API in the Browser.
98
+
99
+ For testing purpose you can use `https://ebay.hendt.workers.dev/` url as proxy. You can also set up your own Proxy server. We have added a example for cloudfront workers: [https://github.com/hendt/ebay-api/blob/master/proxy/worker.js](https://github.com/hendt/ebay-api/blob/master/proxy/worker.js)
100
+
101
+ Or use [https://github.com/Rob--W/cors-anywhere](CORS Anywhere is a NodeJS proxy) (works very well with heroku.com).
102
+
103
+
104
+ ```html
105
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ebay-api@latest/lib/ebay-api.min.js"></script>
106
+ <script>
107
+ const eBay = new eBayApi({
108
+ appId: 'appId',
109
+ certId: 'certId',
110
+ sandbox: false
111
+ });
112
+
113
+ // eBay.req.instance is AxiosInstance per default
114
+ eBay.req.instance.interceptors.request.use((request) => {
115
+ // Add Proxy
116
+ request.url = 'https://ebay.hendt.workers.dev/' + request.url;
117
+ return request;
118
+ });
51
119
 
52
- ### `xmlRequest(options, callback)`
120
+ eBay.buy.browse.getItem('v1|254188828753|0').then(item => {
121
+ console.log(JSON.stringify(item, null, 2));
122
+ }).catch(e => {
123
+ console.error(e);
124
+ });
125
+ </script>
126
+ ```
127
+
128
+ ## 🔧 eBayApi Config
129
+ The first (required) parameter in eBayApi instance takes an object with following properties:
130
+
131
+ | Name | Occurrence | Description |
132
+ | :--- | :--- | :--- |
133
+ | appId | Required | App ID \(Client ID\) from [Application Keys](https://developer.ebay.com/my/keys). |
134
+ | certId | Required | Cert ID \(Client Secret\) from [Application Keys](https://developer.ebay.com/my/keys). |
135
+ | devId | Conditionally | The Dev Id from [Application Keys](https://developer.ebay.com/my/keys). |
136
+ | sandbox | Required<br><pre>Default: `false`</pre> | If true, the [Sandbox Environment](https://developer.ebay.com/tools/sandbox) will be used. |
137
+ | ruName | Conditionally | The redirect\_url value. [More info](https://developer.ebay.com/api-docs/static/oauth-redirect-uri.html). |
138
+ | autoRefreshToken | Required<pre>Default: `true`</pre> | Auto refresh the token if it's expired. |
139
+ | siteId<br><i>Traditional</i> | Required<br><pre>Default: `SiteId.EBAY_US`</pre> | eBay site to which you want to send the request (Trading API, Shopping API). |
140
+ | authToken<br><i>Traditional</i> | Optional | The Auth'N'Auth token. The traditional authentication and authorization technology used by the eBay APIs. |
141
+ | marketplaceId<br><i>RESTful</i> | Required<br><pre>Default: `MarketplaceId.EBAY_US`</pre> | [Docs](https://developer.ebay.com/api-docs/static/rest-request-components.html#marketpl) REST HTTP Header. X-EBAY-C-MARKETPLACE-ID identifies the user's business context and is specified using a marketplace ID value. Note that this header does not indicate a language preference or consumer location. |
142
+ | scope<br><i>RESTful</i> | Conditionally<bre><pre>Default:<br>`['https://api.ebay.com/oauth/api_scope']` </pre> | The scopes assigned to your application allow access to different API resources and functionality. |
143
+ | endUserCtx<br><i>RESTful</i> | Conditionally recommended<br><i>RESTful</i> | [Docs](https://developer.ebay.com/api-docs/static/rest-request-components.html#headers) X-EBAY\_C\_ENDUSERCTX provides various types of information associated with the request. |
144
+ | contentLanguage<br><i>RESTful</i> | Conditionally required<br><pre>Default: `ContentLanguage.en_US`</pre> | [Docs](https://developer.ebay.com/api-docs/static/rest-request-components.html#headers)Content-Language indicates the locale preferred by the client for the response. |
145
+ | acceptLanguage<br><i>RESTful</i> | Optional<pre>Default: `Locale.en_US`</pre> | [Docs](https://developer.ebay.com/api-docs/static/rest-request-components.html#headers) Accept-Language indicates the natural language the client prefers for the response. This specifies the language the client wants to use when the field values provided in the request body are displayed to consumers. |
146
+
147
+ ## Load config from environment
148
+ Use `eBayApi.fromEnv()` to load data from environment variables.
149
+
150
+ | Name | Value |
151
+ | :--- | :--- |
152
+ | appId | process.env.EBAY_APP_ID |
153
+ | certId | process.env.EBAY_CERT_ID |
154
+ | devId | process.env.EBAY_DEV_ID |
155
+ | authToken | process.env.EBAY_AUTH_TOKEN |
156
+ | siteId | process.env.EBAY_SITE_ID |
157
+ | marketplaceId | process.env.EBAY_MARKETPLACE_ID |
158
+ | ruName | process.env.EBAY_RU_NAME |
159
+ | sandbox | process.env.EBAY_SANDBOX === 'true' |
160
+
161
+ ## 🐞 Debug
162
+ To see debug logs use `DEBUG=ebay:*` environment variable.
163
+
164
+ ## 🔑 Access token types
165
+ See the full Documentation [here](https://developer.ebay.com/api-docs/static/oauth-token-types.html).
166
+
167
+ *Client credentials grant flow* mints a new Application access token.
168
+ *Authorization code grant flow* mints a new User access token.
169
+
170
+ ### User access token (authorization code grant flow)
171
+ 👉 Recommended for all API Calls.
172
+
173
+ > You must employ a User token to call any interface that accesses or modifies data that is owned by the user (such as user information and account data).
174
+ To get a User token, the users of your app must grant your application the permissions it needs to act upon their behalf. This process is called user consent. With the user consent flow, each User token contains the set of scopes for which the user has granted their permission [(eBay Token Types)](https://developer.ebay.com/api-docs/static/oauth-token-types.html).
175
+
176
+ ### Application access token (client credentials grant flow)
177
+ 👉 Recommended for API calls that will only request application data (`GET` method, and it's also restricted).
178
+
179
+ > Application tokens are general-use tokens that give access to interfaces that return application data. For example, many GET requests require only an Application token for authorization.
180
+ [(eBay Token Types)](https://developer.ebay.com/api-docs/static/oauth-token-types.html)
181
+
182
+ If no other token is set, this token will be obtained *automatically* in the process of calling an RESTful API.
183
+
184
+ ### Auth'N'Auth
185
+ 👉 The "old" way. Only works with Traditional API.
186
+ Checkout the [Auth'N'Auth example](https://github.com/hendt/ebay-api/tree/master/examples/traditional/authNAuth.ts).
187
+
188
+ You can also generate the token on eBay developer page and use it directly (see Detailed configuration example).
189
+
190
+ ## OAuth2: Exchanging the authorization code for a User access token
191
+
192
+ [eBay Docs](https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html)
53
193
 
54
- Makes an XML POST to an eBay API endpoints.
194
+ ```javascript
195
+ import eBayApi from 'ebay-api';
196
+
197
+ // 1. Create new eBayApi instance and set the scope.
198
+ const eBay = eBayApi.fromEnv();
199
+
200
+ eBay.OAuth2.setScope([
201
+ 'https://api.ebay.com/oauth/api_scope',
202
+ 'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
203
+ 'https://api.ebay.com/oauth/api_scope/sell.fulfillment'
204
+ ]);
205
+
206
+ // 2. Generate and open Url and Grant Access
207
+ const url = eBay.OAuth2.generateAuthUrl();
208
+ console.log('Open URL', url);
209
+ ```
210
+
211
+ After you granted success, eBay will redirect you to your 'Auth accepted URL' and add a query parameter `code`
212
+
213
+
214
+ ### Express example
215
+ This is how it would look like if you use `express`:
216
+
217
+ ```javascript
218
+ import eBayApi from 'ebay-api';
55
219
 
56
- `options` must contain:
220
+ app.get('/success', async function(req, res) {
221
+ // 3. Get the parameter code that is placed as query parameter in redirected page
222
+ const code = req.query.code; // this is provided from eBay
223
+ const eBay = eBayApi.fromEnv(); // or use new eBayApi()
57
224
 
58
- - `serviceName`: e.g. 'Finding'
59
- - `opType`: e.g. 'findItemsAdvanced'
60
- - `appId`: your eBay API application ID
61
-
62
- and can optionally contain:
63
-
64
- - `params`: (see [examples][examples] and API documentation)
65
- - `reqOptions`: passed to the [request][request] module,
66
- e.g. for additional `headers`, or `timeout`.
67
- - `xmlConverter`: function which takes the response XML and converts to JSON.
68
- _Module uses [xml2js](https://www.npmjs.com/package/xml2js) by default, but can be overridden._
69
- - `parser`: function which takes the response data (as JSON object) and extracts items
70
- (or other units depending on the query).
71
- _Module includes a default parser._
72
- - `sandbox`: boolean (default false = production). May need to add additional endpoint URLs to the code as needed.
73
- - `raw`: boolean, set `true` to skip parsing and return the raw XML response.
74
- - `parseDepth`: how many levels down to try to parse/interpret the response.
75
- _The default parser is still experimental._ Set this to 0 or 1 to let your app do all the parsing.
76
- (Default: unlimited)
225
+ try {
226
+ const token = await eBay.OAuth2.getToken(code);
227
+ eBay.OAuth2.setCredentials(token);
228
+ // store this token e.g. to a session
229
+ req.session.token = token
230
+
231
+ // 5. Start using the API
232
+ const orders = await eBay.sell.fulfillment.getOrders()
233
+ res.send(orders);
234
+ } catch(e) {
235
+ console.error(e)
236
+ res.sendStatus(400)
237
+ }
238
+ });
239
+ ```
240
+
241
+ If token is already in session:
242
+
243
+ ```js
244
+ import eBayApi from 'ebay-api';
245
+
246
+ app.get('/orders/:id', async function(req, res) {
247
+ const id = req.params.id;
248
+ const eBay = eBayApi.fromEnv(); // or use new eBayApi(...)
249
+ const token = req.session.token;
250
+ if (!token) {
251
+ return res.sendStatus(403);
252
+ }
253
+
254
+ eBay.OAuth2.setCredentials(token);
77
255
 
78
- _for authentication, include:_
79
-
80
- - `devId`
81
- - `certId`
82
- - `authToken`
83
-
84
- `callback` gets `(error, data)`.
85
-
86
-
87
- ## Helpers
88
-
89
- ### `flatten(obj)`
90
-
91
- Simplifies the JSON format of the API responses:
92
-
93
- - Single-element arrays and objects are flatted to their key:value pair.
94
- - The structure of the format `{ @key:KEY, __value__:VALUE }` is flattened to its key:value pair.
95
- - Other weird structures (from the API itself, or the XML->JSON conversion) are simplified. _(See the code for details.)_
96
-
97
- Its purpose is to make the data easier to handle in code, and to model/query in MongoDB.
98
-
99
- Runs synchronously, returns flattened object.
100
-
101
- The default parser will `flatten()` the response to a finite depth
102
- (because infinite recursion on an indeterminate response size would cause an unnecessary performance hit).
103
- If you want to flatten further, use this method directly.
104
-
105
-
106
- ### `parseResponseJson(data, options, callback)`
107
-
108
- The default parser. Can be overridden (see `options` on `xmlRequest()`).
109
-
110
-
111
- ### `convertXmlToJson(xmlBody, options, callback)`
112
-
113
- The default XML->JS converter. Uses xml2js. Can be overridden (see `options` on `xmlRequest()`).
114
-
115
-
116
- ### `getLatestApiVersions(callback)`
117
-
118
- _Disabled in 1.x. Please submit a PR with a fix/refactor if you use this._
119
-
120
- Get the version numbers of the APIs that make their version available.
121
-
122
-
123
- ## Errors
124
-
125
- The client exports and attempts to differentiate between `EbaySystemError`, `EbayRequestError`, and `EbayClientError`.
126
-
127
- An `EbayAuthenticationError` is also defined, but not yet hooked up to anything.
128
-
129
- See http://developer.ebay.com/DevZone/Shopping/docs/CallRef/types/ErrorClassificationCodeType.html
130
- and http://developer.ebay.com/devzone/xml/docs/Reference/ebay/Errors/ErrorMessages.htm.
131
-
256
+ // If token get's refreshed
257
+ eBay.OAuth2.on('refreshAuthToken', (token) => {
258
+ req.session.token = token;
259
+ });
260
+
261
+ try {
262
+ // 5. Start using the API
263
+ const order = await eBay.sell.fulfillment.getOrder(id);
264
+ res.send(order);
265
+ } catch(e) {
266
+ console.error(e)
267
+ res.sendStatus(400)
268
+ }
269
+ });
270
+ ```
271
+
272
+ ## RESTful API
273
+
274
+ ### How to set the Scope
275
+
276
+ ```javascript
277
+ const eBay = new eBayApi({
278
+ // ...
279
+ scope: ['https://api.ebay.com/oauth/api_scope']
280
+ });
281
+
282
+ // Or:
283
+ eBay.OAuth2.setScope([
284
+ 'https://api.ebay.com/oauth/api_scope',
285
+ 'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
286
+ 'https://api.ebay.com/oauth/api_scope/sell.fulfillment'
287
+ ]);
288
+ ```
289
+
290
+ ### Use apix.ebay.com or apiz.ebay.com (beta) endpoints
291
+ For some APIs, eBay use a `apix`/`apiz` subdomain. To use these subdomains you can use `.apix`/`.apiz` before the api call like this:
292
+ ```javascript
293
+ eBay.buy.browse.apix.getItem() // now it will use https://apix.ebay.com
294
+ eBay.buy.browse.apiz.getItem() // now it will use https://apiz.ebay.com
295
+ ```
296
+
297
+ In any case eBay adds a new subdomain, it's also possible to configure whatever you want:
298
+ ```javascript
299
+ eBay.buy.browse.api({subdomain: 'apiy'}).getItem() // now it will use https://apiy.ebay.com
300
+ ```
301
+
302
+ ### How to refresh the token
303
+ If `autoRefreshToken` is set to true (default value) the token will be automatically refreshed when eBay response with `invalid access token` error.
304
+
305
+ Use Event Emitter to get the token when it gets successfully refreshed.
306
+ ```javascript
307
+ eBay.OAuth2.on('refreshAuthToken', (token) => {
308
+ console.log(token)
309
+ // Store this token in DB
310
+ });
311
+
312
+ // for client token
313
+ eBay.OAuth2.on('refreshClientToken', (token) => {
314
+ console.log(token)
315
+ // Store this token in DB
316
+ });
317
+ ```
318
+ To manuel refresh the auth token use `eBay.OAuth2.refreshAuthToken()` and for the client token `eBay.OAuth2.refreshClientToken()`.
319
+ Keep in mind that you need the 'refresh_token' value set.
320
+
321
+ ```javascript
322
+ const token = await eBay.OAuth2.refreshToken();
323
+ // will refresh Auth Token if set, otherwise the client token if set.
324
+ ```
325
+
326
+ ## Additional request headers
327
+ Sometimes you want to add additional headers to the request like a GLOBAL-ID `X-EBAY-SOA-GLOBAL-ID`.
328
+ You have multiple options to do this.
329
+
330
+ ### RESTful API headers
331
+ ```javascript
332
+ const eBay = new eBayApi();
333
+
334
+ eBay.buy.browse.api({headers: {
335
+ 'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
336
+ }}).getItem('v1|382282567190|651094235351').then((item) => {
337
+ console.log(item)
338
+ })
339
+ ```
340
+
341
+ ### Traditional API headers
342
+ You can pass headers directly in the method call in the second parameter:
343
+ ```javascript
344
+ eBay.trading.AddFixedPriceItem({
345
+ Item: {
346
+ Title: 'title',
347
+ Description: {
348
+ __cdata: '<div>test</div>'
349
+ }
350
+ }
351
+ }, {
352
+ headers: {
353
+ 'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
354
+ }
355
+ })
356
+ ```
357
+
358
+ ### Low level: use the Axios interceptor to manipulate the request
359
+ ```javascript
360
+ import eBayApi from 'ebay-api';
361
+ const eBay = new eBayApi(/* { your config here } */);
362
+
363
+ eBay.req.instance.interceptors.request.use((request) => {
364
+ // Add Header
365
+ request.headers['X-EBAY-SOA-GLOBAL-ID'] = 'EBAY-DE';
366
+ return request;
367
+ })
368
+ ```
369
+
370
+ ### Handle JSON GZIP response e.g fetchItemAspects
371
+ You need a decompress library installed like `zlib`.
372
+
373
+ ```bash
374
+ npm install zlib # or yarn add zlib
375
+ ```
376
+
377
+ ```javascript
378
+ import eBayApi from 'ebay-api';
379
+ import zlib from 'zlib';
380
+
381
+ const toString = (data) => new Promise((resolve) => {
382
+ zlib.gunzip(data, (err, output) => {
383
+ if (err) throw err;
384
+ resolve(output.toString());
385
+ });
386
+ });
387
+
388
+ const eBay = new eBayApi(/* { your config here } */);
389
+
390
+ try {
391
+ const data = await eBay.commerce.taxonomy.fetchItemAspects(/* categoryTreeId */);
392
+ const result = await toString(data);
393
+
394
+ console.log(result)
395
+ } catch (e) {
396
+ console.error(e);
397
+ }
398
+ ```
399
+
400
+ ## Controlling Traditional XML request and response
401
+ The second parameter in the traditional API has the following options:
402
+
403
+ ```typescript
404
+ export type Options = {
405
+ raw?: boolean // return raw XML
406
+ parseOptions?: object // https://github.com/NaturalIntelligence/fast-xml-parser
407
+ useIaf?: boolean // use IAF in header instead of Bearer
408
+ headers?: Headers // additional Headers (key, value)
409
+ hook?: (xml) => BodyHeaders // hook into the request to modify the body and headers
410
+ };
411
+ ```
412
+
413
+ [Fast XML](https://github.com/NaturalIntelligence/fast-xml-parser) is used to parse the XML. You can pass the parse option to `parseOptions` parameter.
132
414
 
133
415
  ## Examples
134
416
 
135
- See the [examples][examples] directory.
136
- To run the examples, you need to add your own app key (I don't want my keys to be disabled for abuse!) -
137
- you can get one [here](https://publisher.ebaypartnernetwork.com/PublisherToolsAPI).
138
-
139
-
140
- ## Debugging
141
-
142
- This module uses the [debug](https://github.com/visionmedia/debug) module for internal logging.
143
-
144
- Run your app (or node REPL) with `DEBUG=ebay* ...` to see output.
145
-
417
+ ### Trading - AddFixedPriceItem \(CDATA\)
418
+
419
+ You can submit your description using CDATA if you want to use HTML or XML.
420
+
421
+ ```javascript
422
+ eBay.trading.AddFixedPriceItem({
423
+ Item: {
424
+ Title: 'title',
425
+ Description: {
426
+ __cdata: '<div>test</div>'
427
+ }
428
+ }
429
+ })
430
+ ```
431
+
432
+ ### Trading - ReviseFixedPriceItem (Update the price of an item)
433
+
434
+ ```javascript
435
+ eBay.trading.ReviseFixedPriceItem({
436
+ Item: {
437
+ ItemID: 'itemId',
438
+ StartPrice: 'startPrice'
439
+ }
440
+ })
441
+ ```
442
+
443
+ ### Buy - getItem
444
+
445
+ ```javascript
446
+ eBay.buy.browse.getItem('v1|382282567190|651094235351').then(a => {
447
+ console.log(a);
448
+ }).catch(e => {
449
+ console.log(e)
450
+ });
451
+ ```
452
+
453
+ ### Post-Order - getReturn
454
+
455
+ ```javascript
456
+ eBay.postOrder.return.getReturn('5132021997').then(a => {
457
+ console.log(a);
458
+ }).catch(e => {
459
+ console.log(e)
460
+ });
461
+ ```
462
+
463
+ ### Finding - findItemsByProduct \(use XML attributes and value\)
464
+
465
+ ```javascript
466
+ eBay.finding.findItemsByProduct({
467
+ productId: {
468
+ '@_type': 'ReferenceID',
469
+ '#value': '53039031'
470
+ }
471
+ })
472
+
473
+ // will produce:
474
+ // <productId type="ReferenceID">53039031</productId>
475
+ ```
476
+
477
+ ### Finding - findItemsIneBayStores
478
+
479
+ ```javascript
480
+ eBay.finding.findItemsIneBayStores({
481
+ storeName: 'HENDT'
482
+ }, {raw: true}).then(result => {
483
+ // Return raw XML
484
+ console.log(result);
485
+ });
486
+ ```
487
+
488
+ ### Finding - findItemsAdvanced \(findItemsByKeywords\)
489
+
490
+ ```javascript
491
+ eBay.finding.findItemsAdvanced({
492
+ itemFilter: [{
493
+ name: 'Seller',
494
+ value: 'hendt_de'
495
+ }],
496
+ keywords: 'katze'
497
+ }).then(result => {
498
+ console.log(result);
499
+ });
500
+ ```
501
+
502
+ ### Trading - GetMyeBaySelling
503
+
504
+ ```javascript
505
+ eBay.trading.GetMyeBaySelling({
506
+ SoldList: {
507
+ Include: true,
508
+ Pagination: {
509
+ EntriesPerPage: 20,
510
+ PageNumber: 1
511
+ }
512
+ }
513
+ }).then(data => {
514
+ console.log(data.results)
515
+ });
516
+ ```
517
+
518
+ ## FAQ
519
+ 1. Do I need the [eBay OAuth Client](https://www.npmjs.com/package/ebay-oauth-nodejs-client) dependency?
520
+
521
+ No. This library has already all authentication implemented and support also auto refreshing token.
522
+
523
+ 2. What does IAF mean?
524
+
525
+ IAF stands for IDENTITY ASSERTION FRAMEWORK.
526
+ The traditional API supports IAF. That means you can use the OAuth2 token with the traditional APIs.
527
+
528
+ 3. Is it possible to Upload Pictures directly to EPS?
529
+
530
+ Yes. Checkout the [Browser](https://hendt.github.io/ebay-api/) example and [Node Example here](https://github.com/hendt/ebay-api/blob/master/examples/traditional/trading.UploadSiteHostedPictures.ts).
531
+
532
+ ## Contribution
533
+
534
+ Check [here](https://github.com/hendt/ebay-api/blob/master/CONTRIBUTING.md)
535
+
536
+ ## Supported By
537
+
538
+ [hendt.de](https://hendt.de)
539
+ [rootle.de](https://rootle.de)
540
+
541
+ ## 📝 License
146
542
 
147
- [network]: https://github.com/benbuckman/nodejs-ebay-api/network
148
- [examples]: https://github.com/benbuckman/nodejs-ebay-api/tree/master/examples
149
- [request]: https://github.com/request/request
543
+ MIT.