forked from hendt/ebay-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
259 lines (232 loc) · 6.28 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>eBay API Browser example</title>
<meta name="description" content="eBay Node API in TypeScript with Browser support">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<style>
label {
display: block;
margin: 10px 0;
display: flex;
}
label > span {
display: inline-block;
min-width: 130px;
flex-shrink: 0;
}
input[type="text"], input[type="number"] {
border-radius: 3px;
border: 1px solid #ccc;
line-height: 2;
width: 100%;
}
#response {
width: 600px;
min-height: 300px;
}
.submit {
border: none;
background: #fff;
border-radius: 3px;
padding: 5px;
flex-shrink: 0;
margin: 5px;
color: rgb(12, 171, 252);
border: 1px solid #E6ECF1;
box-shadow: 0 3px 8px 0 rgb(116 129 141 / 10%);
}
html, body {
padding: 0;
margin: 0;
height: 100%;
}
body {
background: #fff;
font-family: 'Poppins', sans-serif;
}
main {
display: flex;
height: 100%;
}
#sidebar {
height: 100vh;
background: #F5F7F9;
border-right: 1px solid #E6ECF1;
padding: 0 5px;
flex-shrink: 0;
}
#result {
padding: 0 10px;
overflow: auto;
}
fieldset {
border-radius: 4px;
border-color: #fff;
padding: 5px;
}
@media all and (max-width: 800px) {
main {
flex-wrap: wrap;
}
#sidebar {
height: auto;
width: 100%;
}
label {
flex-direction: column;
}
}
</style>
</head>
<body>
<!-- script type="text/javascript" src="./lib/ebay-api.min.js"></script -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ebay-api@latest/lib/ebay-api.min.js"></script>
<link rel="stylesheet"
href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css">
<script src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<script
charset="UTF-8"
src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.9/languages/json.min.js"></script>
<main>
<div id="sidebar">
<form onsubmit="event.preventDefault()">
<div>
<fieldset>
<legend>Credentials</legend>
<label>
<span>AppId:<span style="color:red">*</span></span>
<input name="appId" placeholder="appId" type="text">
</label>
<label>
<span>Cert ID<span style="color:red">*</span></span>
<input name="certId" placeholder="certId" type="text">
</label>
<label>
<span>Dev ID</span>
<input name="devId" placeholder="DevId" type="text">
</label>
<label>
<span>Access Token</span>
<textarea rows="4" cols="50" name="accessToken" placeholder="accessToken"></textarea>
</label>
</fieldset>
<fieldset>
<legend>Config</legend>
<label>
<span>SiteId</span>
<input type="number" value="0" name="siteId">
</label>
<label>
<span>Marketplace Id</span>
<input type="text" value="EBAY_US" name="marketplaceId">
</label>
<label>
<span>Sandbox</span>
<input type="checkbox" name="sandbox">
</label>
</fieldset>
</div>
<label>
<span>Get Item</span>
<input value="254188828753" name="itemId" type="text">
<button type="submit" class="submit" onclick="getItem()">Get Item</button>
</label>
<label>
<span>Search</span>
<input value="" name="query" type="text">
<button type="submit" class="submit" onclick="search()">Search</button>
</label>
<label>
<span>Upload to EPS</span>
<input type="file" name="image">
<button type="submit" class="submit" onclick="upload()">Upload</button>
</label>
</form>
</div>
<div id="result">
<h1>eBay API Browser - Playground</h1>
<ul>
<li><a href="https://hendt.gitbook.io/ebay-api/" target="_blank">Documentation</a></li>
<li><a href="https://github.com/hendt/ebay-api" target="_blank">GitHub</a></li>
</ul>
<p>This API use <span style="font-family: monospace;color: #333">https://ebay.hendt.workers.dev/</span> as a Proxy.</p>
<p>It's only mention for testing, do not abuse it or use in production.</p>
<pre><code id="code"></code></pre>
</div>
</main>
<script type="text/javascript">
const form = document.forms[0]
const code = document.getElementById('code')
function createApi() {
code.innerText = 'Loading...'
const eBay = new eBayApi({
appId: form.appId.value,
certId: form.certId.value,
devId: form.devId.value,
sandbox: form.sandbox.checked,
siteId: parseInt(form.siteId.value, 10),
marketplaceId: form.marketplaceId.value,
contentLanguage: 'en-US'
});
eBay.req.instance.interceptors.request.use((request) => {
request.url = 'https://ebay.hendt.workers.dev/' + request.url;
return request;
})
if (form.accessToken.value) {
eBay.OAuth2.setCredentials(form.accessToken.value.trim());
}
return eBay
}
function handleError(e) {
console.error(e);
code.innerText = e.message
}
function handleResponse(data) {
code.innerText = JSON.stringify(data, null, 2);
hljs.highlightBlock(code);
}
function getItem() {
try {
createApi().buy.browse.getItem('v1|' + form.itemId.value + '|0').then(handleResponse)
.catch(handleError);
} catch (e) {
handleError(e)
}
}
function search() {
try {
createApi().buy.browse.search({q: form.query}).then(handleResponse)
.catch(handleError);
} catch (e) {
handleError(e)
}
}
function upload() {
const file = document.forms[0].image.files[0];
if (!file) {
alert('File is required.');
return;
}
try {
createApi().trading.UploadSiteHostedPictures({ExtensionInDays: 1}, {
hook: (xml) => {
const formData = new FormData();
// XML should be always first
formData.append('XML Payload', xml);
formData.append('image', file);
return {
body: formData,
headers: {'Content-Type': 'multipart/form-data'}
}
}
}).then(handleResponse)
.catch(handleError);
} catch (e) {
handleError(e)
}
}
</script>
</body>