ebay-api 8.2.0 → 8.4.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.
- package/README.md +37 -2
- package/dist/api/digitalSignature.d.ts +43 -0
- package/dist/api/digitalSignature.js +105 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +18 -0
- package/dist/api/restful/developer/keyManagement/index.d.ts +2 -4
- package/dist/api/restful/developer/keyManagement/index.js +5 -3
- package/dist/api/restful/index.d.ts +12 -7
- package/dist/api/restful/index.js +30 -17
- package/dist/api/restful/sell/marketing/index.d.ts +184 -1
- package/dist/api/restful/sell/marketing/index.js +260 -0
- package/dist/api/traditional/XMLRequest.d.ts +3 -1
- package/dist/api/traditional/XMLRequest.js +3 -1
- package/dist/api/traditional/index.d.ts +1 -1
- package/dist/api/traditional/index.js +25 -15
- package/dist/eBayApi.d.ts +2 -1
- package/dist/eBayApi.js +12 -1
- package/dist/ebay-api.min.mjs +1 -1
- package/dist/errors/index.js +5 -0
- package/dist/types/apiTypes.d.ts +7 -0
- package/dist/types/restfulTypes.d.ts +90 -0
- package/dist/types/traditonalTypes.d.ts +2 -1
- package/lib/api/digitalSignature.d.ts +43 -0
- package/lib/api/digitalSignature.js +112 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +18 -0
- package/lib/api/restful/developer/keyManagement/index.d.ts +2 -4
- package/lib/api/restful/developer/keyManagement/index.js +5 -3
- package/lib/api/restful/index.d.ts +12 -7
- package/lib/api/restful/index.js +34 -21
- package/lib/api/restful/sell/marketing/index.d.ts +184 -1
- package/lib/api/restful/sell/marketing/index.js +260 -0
- package/lib/api/traditional/XMLRequest.d.ts +3 -1
- package/lib/api/traditional/XMLRequest.js +2 -0
- package/lib/api/traditional/index.d.ts +1 -1
- package/lib/api/traditional/index.js +29 -19
- package/lib/eBayApi.d.ts +2 -1
- package/lib/eBayApi.js +12 -1
- package/lib/ebay-api.min.js +1 -1
- package/lib/errors/index.js +5 -0
- package/lib/types/apiTypes.d.ts +7 -0
- package/lib/types/restfulTypes.d.ts +90 -0
- package/lib/types/traditonalTypes.d.ts +2 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ It supports `client credentials grant` and `authorization code grant` \(Auth'N'A
|
|
|
21
21
|
|
|
22
22
|
## Changelog
|
|
23
23
|
|
|
24
|
-
* `v8.
|
|
24
|
+
* `v8.4.0` is the latest release.
|
|
25
25
|
* See [here](https://github.com/hendt/ebay-api/blob/master/CHANGELOG.md) for the full changelog.
|
|
26
26
|
|
|
27
27
|
## Implementation status
|
|
@@ -34,7 +34,7 @@ It supports `client credentials grant` and `authorization code grant` \(Auth'N'A
|
|
|
34
34
|
| **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` |
|
|
35
35
|
| **Developer API** | ✔ Analytics API |
|
|
36
36
|
| **Post Order API** | ✔ Cancellation API<br>✔ Case Management API<br>✔ Inquiry API<br>✔ Return API |
|
|
37
|
-
| **Sell API** | ✔ Account API `v1.9.0`<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.
|
|
37
|
+
| **Sell API** | ✔ Account API `v1.9.0`<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.14.0`<br>✔ Metadata API<br>✔ Negotiation API `v1.1.0`<br>✔ Recommendation API `v1.1.0` |
|
|
38
38
|
|
|
39
39
|
### Traditional API
|
|
40
40
|
|
|
@@ -306,6 +306,41 @@ app.get('/orders/:id', async function (req, res) {
|
|
|
306
306
|
});
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
+
## Digital Signature
|
|
310
|
+
Signatures are required when the call is made for EU- or UK-domiciled sellers, and only for the following APIs/methods:
|
|
311
|
+
|
|
312
|
+
* All methods in the Finances API
|
|
313
|
+
* issueRefund in the Fulfillment API
|
|
314
|
+
* GetAccount in the Trading API
|
|
315
|
+
* The following methods in the Post-Order API:
|
|
316
|
+
- Issue Inquiry Refund
|
|
317
|
+
- Issue case refund
|
|
318
|
+
- Issue return refund
|
|
319
|
+
- Process Return Request
|
|
320
|
+
- Create Cancellation Request
|
|
321
|
+
- Approve Cancellation Request
|
|
322
|
+
|
|
323
|
+
### How to use Digital Signature
|
|
324
|
+
```js
|
|
325
|
+
// 1. Create singning key and save it appropriatly
|
|
326
|
+
const signingKey = await eBay.developer.keyManagement.createSigningKey('ED25519');
|
|
327
|
+
// 2. Set the signature
|
|
328
|
+
eBay.setSignature(signingKey)
|
|
329
|
+
// or in constructor
|
|
330
|
+
eBay = new eBayApi({
|
|
331
|
+
appId: '...',
|
|
332
|
+
certId: '...',
|
|
333
|
+
signature: {
|
|
334
|
+
jwe: signingKey.jwe,
|
|
335
|
+
privateKey: signingKey.privateKey
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
// 3. Use the 'sign' keyword in Restful API
|
|
339
|
+
const summary = await eBay.sell.finances.sign.getSellerFundsSummary();
|
|
340
|
+
// 3. Or the 'sign' parameter in traditional API
|
|
341
|
+
const account = await eBay.trading.GetAccount(null, {sign: true});
|
|
342
|
+
```
|
|
343
|
+
|
|
309
344
|
## RESTful API
|
|
310
345
|
|
|
311
346
|
### How to set the Scope
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Cipher, Headers } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the 'Content-Digest' header value for the input payload.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} payload The request payload.
|
|
6
|
+
* @param {string} cipher The algorithm used to calculate the digest.
|
|
7
|
+
* @returns {string} contentDigest The 'Content-Digest' header value.
|
|
8
|
+
*/
|
|
9
|
+
export declare const generateContentDigestValue: (payload: unknown, cipher?: Cipher) => string;
|
|
10
|
+
export type SignatureComponents = {
|
|
11
|
+
method: string;
|
|
12
|
+
authority: string;
|
|
13
|
+
path: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Generates the base string.
|
|
17
|
+
*
|
|
18
|
+
* @param {any} headers The HTTP request headers.
|
|
19
|
+
* @param {SignatureComponents} signatureComponents The config.
|
|
20
|
+
* @param {any} payload The payload.
|
|
21
|
+
* @param {number} timestamp The timestamp.
|
|
22
|
+
* @returns {string} payload The base string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateBaseString(headers: Headers, signatureComponents: SignatureComponents, payload: any, timestamp?: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Generates the Signature-Input header value for the input payload.
|
|
27
|
+
*
|
|
28
|
+
* @param {any} payload The input config.
|
|
29
|
+
* @param {number} timestamp The timestamp.
|
|
30
|
+
* @returns {string} the 'Signature-Input' header value.
|
|
31
|
+
*/
|
|
32
|
+
export declare const generateSignatureInput: (payload: any, timestamp?: number) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Generates the 'Signature' header.
|
|
35
|
+
*
|
|
36
|
+
* @param {any} headers The HTTP headers.
|
|
37
|
+
* @param {string} privateKey The HTTP headers.
|
|
38
|
+
* @param {SignatureComponents} signatureComponents The signature components
|
|
39
|
+
* @param {any} payload The payload
|
|
40
|
+
* @param {number} timestamp The payload
|
|
41
|
+
* @returns {string} the signature header value.
|
|
42
|
+
*/
|
|
43
|
+
export declare function generateSignature(headers: any, privateKey: string, signatureComponents: SignatureComponents, payload: any, timestamp?: number): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createHash, sign } from 'crypto';
|
|
2
|
+
const beginPrivateKey = '-----BEGIN PRIVATE KEY-----';
|
|
3
|
+
const endPrivateKey = '-----END PRIVATE KEY-----';
|
|
4
|
+
// based on https://github.com/ebay/digital-signature-nodejs-sdk
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current UNIX timestamp.
|
|
7
|
+
*
|
|
8
|
+
* @returns {number} The unix timestamp.
|
|
9
|
+
*/
|
|
10
|
+
const getUnixTimestamp = () => Date.now() / 1000 | 0;
|
|
11
|
+
const getSignatureParams = (payload) => [
|
|
12
|
+
...payload ? ['content-digest'] : [],
|
|
13
|
+
'x-ebay-signature-key',
|
|
14
|
+
'@method',
|
|
15
|
+
'@path',
|
|
16
|
+
'@authority'
|
|
17
|
+
];
|
|
18
|
+
const getSignatureParamsValue = (payload) => getSignatureParams(payload).map(param => `"${param}"`).join(' ');
|
|
19
|
+
/**
|
|
20
|
+
* Generates the 'Content-Digest' header value for the input payload.
|
|
21
|
+
*
|
|
22
|
+
* @param {any} payload The request payload.
|
|
23
|
+
* @param {string} cipher The algorithm used to calculate the digest.
|
|
24
|
+
* @returns {string} contentDigest The 'Content-Digest' header value.
|
|
25
|
+
*/
|
|
26
|
+
export const generateContentDigestValue = (payload, cipher = 'sha256') => {
|
|
27
|
+
const payloadBuffer = Buffer.from(typeof payload === 'string' ? payload : JSON.stringify(payload));
|
|
28
|
+
const hash = createHash(cipher).update(payloadBuffer).digest('base64');
|
|
29
|
+
const algo = cipher === 'sha512' ? 'sha-512' : 'sha-256';
|
|
30
|
+
return `${algo}=:${hash}:`;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Generates the base string.
|
|
34
|
+
*
|
|
35
|
+
* @param {any} headers The HTTP request headers.
|
|
36
|
+
* @param {SignatureComponents} signatureComponents The config.
|
|
37
|
+
* @param {any} payload The payload.
|
|
38
|
+
* @param {number} timestamp The timestamp.
|
|
39
|
+
* @returns {string} payload The base string.
|
|
40
|
+
*/
|
|
41
|
+
export function generateBaseString(headers, signatureComponents, payload, timestamp = getUnixTimestamp()) {
|
|
42
|
+
try {
|
|
43
|
+
let baseString = '';
|
|
44
|
+
const signatureParams = getSignatureParams(payload);
|
|
45
|
+
signatureParams.forEach(param => {
|
|
46
|
+
baseString += `"${param.toLowerCase()}": `;
|
|
47
|
+
if (param.startsWith('@')) {
|
|
48
|
+
switch (param.toLowerCase()) {
|
|
49
|
+
case '@method':
|
|
50
|
+
baseString += signatureComponents.method;
|
|
51
|
+
break;
|
|
52
|
+
case '@authority':
|
|
53
|
+
baseString += signatureComponents.authority;
|
|
54
|
+
break;
|
|
55
|
+
case '@path':
|
|
56
|
+
baseString += signatureComponents.path;
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
throw new Error('Unknown pseudo header ' + param);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (!headers[param]) {
|
|
64
|
+
throw new Error('Header ' + param + ' not included in message');
|
|
65
|
+
}
|
|
66
|
+
baseString += headers[param];
|
|
67
|
+
}
|
|
68
|
+
baseString += '\n';
|
|
69
|
+
});
|
|
70
|
+
baseString += `"@signature-params": (${getSignatureParamsValue(payload)});created=${timestamp}`;
|
|
71
|
+
return baseString;
|
|
72
|
+
}
|
|
73
|
+
catch (ex) {
|
|
74
|
+
throw new Error(`Error calculating signature base: ${ex.message}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generates the Signature-Input header value for the input payload.
|
|
79
|
+
*
|
|
80
|
+
* @param {any} payload The input config.
|
|
81
|
+
* @param {number} timestamp The timestamp.
|
|
82
|
+
* @returns {string} the 'Signature-Input' header value.
|
|
83
|
+
*/
|
|
84
|
+
export const generateSignatureInput = (payload, timestamp = getUnixTimestamp()) => `sig1=(${getSignatureParamsValue(payload)});created=${timestamp}`;
|
|
85
|
+
/**
|
|
86
|
+
* Generates the 'Signature' header.
|
|
87
|
+
*
|
|
88
|
+
* @param {any} headers The HTTP headers.
|
|
89
|
+
* @param {string} privateKey The HTTP headers.
|
|
90
|
+
* @param {SignatureComponents} signatureComponents The signature components
|
|
91
|
+
* @param {any} payload The payload
|
|
92
|
+
* @param {number} timestamp The payload
|
|
93
|
+
* @returns {string} the signature header value.
|
|
94
|
+
*/
|
|
95
|
+
export function generateSignature(headers, privateKey, signatureComponents, payload, timestamp = getUnixTimestamp()) {
|
|
96
|
+
const baseString = generateBaseString(headers, signatureComponents, payload, timestamp);
|
|
97
|
+
privateKey = privateKey.trim();
|
|
98
|
+
if (!privateKey.startsWith(beginPrivateKey)) {
|
|
99
|
+
privateKey = beginPrivateKey + '\n' + privateKey + '\n' + endPrivateKey;
|
|
100
|
+
}
|
|
101
|
+
const signatureBuffer = sign(undefined, // If algorithm is undefined, then it is dependent upon the private key type.
|
|
102
|
+
Buffer.from(baseString), privateKey);
|
|
103
|
+
const signature = signatureBuffer.toString('base64');
|
|
104
|
+
return `sig1=:${signature}:`;
|
|
105
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ import Auth from '../auth/index.js';
|
|
|
2
2
|
import { IEBayApiRequest } from '../request.js';
|
|
3
3
|
import { AppConfig } from '../types/index.js';
|
|
4
4
|
import Base from './base.js';
|
|
5
|
+
import { SignatureComponents } from './digitalSignature.js';
|
|
5
6
|
/**
|
|
6
7
|
* Superclass with Auth container.
|
|
7
8
|
*/
|
|
8
9
|
export default abstract class Api extends Base {
|
|
9
10
|
readonly auth: Auth;
|
|
10
11
|
constructor(config: AppConfig, req?: IEBayApiRequest, auth?: Auth);
|
|
12
|
+
getDigitalSignatureHeaders(signatureComponents: SignatureComponents, payload: any): {};
|
|
11
13
|
}
|
package/dist/api/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Auth from '../auth/index.js';
|
|
2
2
|
import Base from './base.js';
|
|
3
|
+
import { generateContentDigestValue, generateSignature, generateSignatureInput } from './digitalSignature.js';
|
|
3
4
|
/**
|
|
4
5
|
* Superclass with Auth container.
|
|
5
6
|
*/
|
|
@@ -8,4 +9,21 @@ export default class Api extends Base {
|
|
|
8
9
|
super(config, req);
|
|
9
10
|
this.auth = auth || new Auth(this.config, this.req);
|
|
10
11
|
}
|
|
12
|
+
getDigitalSignatureHeaders(signatureComponents, payload) {
|
|
13
|
+
if (!this.config.signature) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
const digitalSignatureHeaders = {
|
|
17
|
+
'x-ebay-enforce-signature': true,
|
|
18
|
+
'x-ebay-signature-key': this.config.signature.jwe,
|
|
19
|
+
...payload ? {
|
|
20
|
+
'content-digest': generateContentDigestValue(payload, this.config.signature.cipher ?? 'sha256')
|
|
21
|
+
} : {},
|
|
22
|
+
'signature-input': generateSignatureInput(payload)
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
...digitalSignatureHeaders,
|
|
26
|
+
'signature': generateSignature(digitalSignatureHeaders, this.config.signature.privateKey, signatureComponents, payload)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
11
29
|
}
|
|
@@ -12,11 +12,9 @@ export default class KeyManagement extends Restful {
|
|
|
12
12
|
*/
|
|
13
13
|
getSigningKeys(): Promise<any>;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* This method creates keypairs.
|
|
16
16
|
*/
|
|
17
|
-
createSigningKey(
|
|
18
|
-
signingKeyCipher: string;
|
|
19
|
-
}): Promise<any>;
|
|
17
|
+
createSigningKey(signingKeyCipher: 'ED25519' | 'RSA'): Promise<any>;
|
|
20
18
|
/**
|
|
21
19
|
* This method returns the <b>Public Key</b>, <b>Public Key as JWE</b>,
|
|
22
20
|
* and metadata for a specified <code>signingKeyId</code> associated with the application key making the call.
|
|
@@ -17,10 +17,12 @@ export default class KeyManagement extends Restful {
|
|
|
17
17
|
return this.get(`/signing_key`);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* This method creates keypairs.
|
|
21
21
|
*/
|
|
22
|
-
createSigningKey(
|
|
23
|
-
return this.post(`/signing_key`,
|
|
22
|
+
createSigningKey(signingKeyCipher) {
|
|
23
|
+
return this.post(`/signing_key`, {
|
|
24
|
+
signingKeyCipher
|
|
25
|
+
});
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* This method returns the <b>Public Key</b>, <b>Public Key as JWE</b>,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import Api from '../index.js';
|
|
2
1
|
import Auth from '../../auth/index.js';
|
|
3
2
|
import { IEBayApiRequest } from '../../request.js';
|
|
4
3
|
import { ApiRequestConfig, AppConfig } from '../../types/index.js';
|
|
4
|
+
import Api from '../index.js';
|
|
5
5
|
export declare const defaultApiHeaders: Record<string, string>;
|
|
6
6
|
export type RestfulApiConfig = {
|
|
7
7
|
subdomain?: string;
|
|
8
8
|
useIaf?: boolean;
|
|
9
|
+
sign?: boolean;
|
|
9
10
|
apiVersion?: string;
|
|
10
11
|
basePath?: string;
|
|
11
12
|
schema?: string;
|
|
@@ -14,7 +15,7 @@ export type RestfulApiConfig = {
|
|
|
14
15
|
} & ApiRequestConfig;
|
|
15
16
|
export type ApiRequest = {
|
|
16
17
|
method: keyof IEBayApiRequest;
|
|
17
|
-
|
|
18
|
+
path: string;
|
|
18
19
|
config?: any;
|
|
19
20
|
data?: any;
|
|
20
21
|
};
|
|
@@ -50,12 +51,16 @@ export default abstract class Restful extends Api {
|
|
|
50
51
|
* Use "apiz" subdomain
|
|
51
52
|
*/
|
|
52
53
|
get apiz(): this;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Sign request
|
|
56
|
+
*/
|
|
57
|
+
get sign(): this;
|
|
58
|
+
get(path: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>;
|
|
59
|
+
delete(path: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>;
|
|
60
|
+
post(path: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>;
|
|
61
|
+
put(path: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>;
|
|
57
62
|
get additionalHeaders(): any;
|
|
58
|
-
enrichRequestConfig(
|
|
63
|
+
enrichRequestConfig(apiRequest: ApiRequest, payload?: any, apiConfig?: Required<RestfulApiConfig>): Promise<any>;
|
|
59
64
|
private doRequest;
|
|
60
65
|
private shouldRefreshToken;
|
|
61
66
|
private request;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Api from '../index.js';
|
|
2
1
|
import { EBayInvalidAccessToken, handleEBayError } from '../../errors/index.js';
|
|
2
|
+
import Api from '../index.js';
|
|
3
3
|
export const defaultApiHeaders = {
|
|
4
4
|
'Content-Type': 'application/json',
|
|
5
5
|
'Cache-Control': 'no-cache',
|
|
@@ -53,7 +53,8 @@ export default class Restful extends Api {
|
|
|
53
53
|
sandbox: this.config.sandbox,
|
|
54
54
|
tld: 'ebay.com',
|
|
55
55
|
headers: {},
|
|
56
|
-
returnResponse: false
|
|
56
|
+
returnResponse: false,
|
|
57
|
+
sign: false
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
get baseUrl() {
|
|
@@ -79,17 +80,23 @@ export default class Restful extends Api {
|
|
|
79
80
|
get apiz() {
|
|
80
81
|
return this.api({ subdomain: 'apiz' });
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Sign request
|
|
85
|
+
*/
|
|
86
|
+
get sign() {
|
|
87
|
+
return this.api({ sign: true });
|
|
88
|
+
}
|
|
89
|
+
async get(path, config = {}, apiConfig) {
|
|
90
|
+
return this.doRequest({ method: 'get', path, config }, apiConfig);
|
|
84
91
|
}
|
|
85
|
-
async delete(
|
|
86
|
-
return this.doRequest({ method: 'delete',
|
|
92
|
+
async delete(path, config = {}, apiConfig) {
|
|
93
|
+
return this.doRequest({ method: 'delete', path, config }, apiConfig);
|
|
87
94
|
}
|
|
88
|
-
async post(
|
|
89
|
-
return this.doRequest({ method: 'post',
|
|
95
|
+
async post(path, data, config = {}, apiConfig) {
|
|
96
|
+
return this.doRequest({ method: 'post', path, data, config }, apiConfig);
|
|
90
97
|
}
|
|
91
|
-
async put(
|
|
92
|
-
return this.doRequest({ method: 'put',
|
|
98
|
+
async put(path, data, config = {}, apiConfig) {
|
|
99
|
+
return this.doRequest({ method: 'put', path, data, config }, apiConfig);
|
|
93
100
|
}
|
|
94
101
|
get additionalHeaders() {
|
|
95
102
|
return Object.keys(additionalHeaders)
|
|
@@ -101,18 +108,24 @@ export default class Restful extends Api {
|
|
|
101
108
|
return headers;
|
|
102
109
|
}, {});
|
|
103
110
|
}
|
|
104
|
-
async enrichRequestConfig(
|
|
111
|
+
async enrichRequestConfig(apiRequest, payload = null, apiConfig = this.apiConfig) {
|
|
105
112
|
const authHeader = await this.auth.getHeaderAuthorization(apiConfig.useIaf);
|
|
113
|
+
const signatureHeaders = apiConfig.sign ? this.getDigitalSignatureHeaders({
|
|
114
|
+
method: apiRequest.method.toUpperCase(),
|
|
115
|
+
authority: Restful.buildServerUrl('', apiConfig.subdomain, apiConfig.sandbox, apiConfig.tld),
|
|
116
|
+
path: apiConfig.apiVersion + apiConfig.basePath + apiRequest.path
|
|
117
|
+
}, payload) : {};
|
|
106
118
|
const headers = {
|
|
107
119
|
...defaultApiHeaders,
|
|
108
120
|
...this.additionalHeaders,
|
|
109
121
|
...authHeader,
|
|
110
|
-
...apiConfig.headers
|
|
122
|
+
...apiConfig.headers,
|
|
123
|
+
...signatureHeaders
|
|
111
124
|
};
|
|
112
125
|
return {
|
|
113
|
-
...config,
|
|
126
|
+
...apiRequest.config,
|
|
114
127
|
headers: {
|
|
115
|
-
...(config.headers || {}),
|
|
128
|
+
...(apiRequest.config.headers || {}),
|
|
116
129
|
...headers
|
|
117
130
|
}
|
|
118
131
|
};
|
|
@@ -139,14 +152,14 @@ export default class Restful extends Api {
|
|
|
139
152
|
return error?.meta?.res?.status === 401 && this.apiConfig.basePath === '/post-order/v2';
|
|
140
153
|
}
|
|
141
154
|
async request(apiRequest, apiConfig = this.apiConfig, refreshToken = false) {
|
|
142
|
-
const {
|
|
155
|
+
const { path, method, data } = apiRequest;
|
|
143
156
|
const apiCfg = { ...this.apiConfig, ...apiConfig };
|
|
144
|
-
const endpoint = this.getServerUrl(apiCfg) +
|
|
157
|
+
const endpoint = this.getServerUrl(apiCfg) + path;
|
|
145
158
|
try {
|
|
146
159
|
if (refreshToken) {
|
|
147
160
|
await this.auth.OAuth2.refreshToken();
|
|
148
161
|
}
|
|
149
|
-
const enrichedConfig = await this.enrichRequestConfig(
|
|
162
|
+
const enrichedConfig = await this.enrichRequestConfig(apiRequest, data, apiCfg);
|
|
150
163
|
const args = ['get', 'delete'].includes(method) ? [enrichedConfig] : [data, enrichedConfig];
|
|
151
164
|
// @ts-ignore
|
|
152
165
|
const response = await this.req[method](endpoint, ...args);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BulkCreateAdRequest, BulkCreateAdsByInventoryReferenceRequest, BulkCreateKeywordRequest, BulkCreateNegativeKeywordRequest, BulkDeleteAdRequest, BulkDeleteAdsByInventoryReferenceRequest, BulkUpdateAdStatusByListingIdRequest, BulkUpdateAdStatusRequest, BulkUpdateKeywordRequest, BulkUpdateNegativeKeywordRequest, CloneCampaignRequest, CreateAdGroupRequest, CreateAdRequest, CreateAdsByInventoryReferenceRequest, CreateCampaignRequest, CreateKeywordRequest, CreateNegativeKeywordRequest, CreateReportTask, ItemPriceMarkdown, ItemPromotion, TargetedBidRequest, TargetedKeywordRequest, UpdateAdGroupRequest, UpdateAdrateStrategyRequest, UpdateBidPercentageRequest, UpdateCampaignBudgetRequest, UpdateCampaignIdentificationRequest, UpdateKeywordRequest, UpdateNegativeKeywordRequest } from '../../../../types/index.js';
|
|
1
2
|
import Restful from '../../index.js';
|
|
2
|
-
import { BulkCreateAdRequest, BulkCreateAdsByInventoryReferenceRequest, BulkDeleteAdRequest, BulkDeleteAdsByInventoryReferenceRequest, CloneCampaignRequest, CreateAdRequest, CreateAdsByInventoryReferenceRequest, CreateCampaignRequest, CreateReportTask, ItemPriceMarkdown, ItemPromotion, UpdateBidPercentageRequest, UpdateCampaignIdentificationRequest } from '../../../../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* <p>The <i>Marketing API </i> offers two platforms that sellers can use to promote and advertise their products:
|
|
5
5
|
* </p> <ul><li><b>Promoted Listings</b> is an eBay ad service that lets sellers set up <i>ad campaigns </i>
|
|
@@ -61,6 +61,22 @@ export default class Marketing extends Restful {
|
|
|
61
61
|
* @param body Container for the bulk request to update ads.
|
|
62
62
|
*/
|
|
63
63
|
bulkUpdateAdsBidByListingId(campaignId: string, body: BulkCreateAdRequest): Promise<any>;
|
|
64
|
+
/**
|
|
65
|
+
* This method is only available for select partners who have been approved for the eBay Promoted Listings Advanced (PLA) program.
|
|
66
|
+
*
|
|
67
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
68
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
69
|
+
* @param body The bulk request to update the ads.
|
|
70
|
+
*/
|
|
71
|
+
bulkUpdateAdsStatus(campaignId: string, body: BulkUpdateAdStatusRequest): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* This method is only available for select partners who have been approved for the eBay Promoted Listings Advanced (PLA) program.
|
|
74
|
+
*
|
|
75
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
76
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
77
|
+
* @param body The bulk request to update ads.
|
|
78
|
+
*/
|
|
79
|
+
bulkUpdateAdsStatusByListingId(campaignId: string, body: BulkUpdateAdStatusByListingIdRequest): Promise<any>;
|
|
64
80
|
/**
|
|
65
81
|
* This method retrieves all the ads for the specified campaign.
|
|
66
82
|
*
|
|
@@ -140,6 +156,57 @@ export default class Marketing extends Restful {
|
|
|
140
156
|
* @param body This type defines the fields for the updateBid request.
|
|
141
157
|
*/
|
|
142
158
|
updateBid(campaignId: string, adId: string, body: UpdateBidPercentageRequest): Promise<any>;
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
162
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
163
|
+
* @param adGroupStatus A comma-separated list of ad group statuses.
|
|
164
|
+
* @param limit The number of results, from the current result set, to be returned in a single page.
|
|
165
|
+
* @param offset The number of results that will be skipped in the result set.
|
|
166
|
+
*/
|
|
167
|
+
getAdGroups(campaignId: string, { adGroupStatus, limit, offset }?: {
|
|
168
|
+
adGroupStatus?: string;
|
|
169
|
+
limit?: number;
|
|
170
|
+
offset?: number;
|
|
171
|
+
}): Promise<any>;
|
|
172
|
+
/**
|
|
173
|
+
*
|
|
174
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
175
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
176
|
+
* @param body This type defines the fields for the <b>createAdGroup</b> request.
|
|
177
|
+
*/
|
|
178
|
+
createAdGroup(campaignId: string, body: CreateAdGroupRequest): Promise<any>;
|
|
179
|
+
/**
|
|
180
|
+
*
|
|
181
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
182
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
183
|
+
* @param adGroupId The ID of the ad group that shall be retrieved.
|
|
184
|
+
*/
|
|
185
|
+
getAdGroup(campaignId: string, adGroupId: string): Promise<any>;
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
189
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
190
|
+
* @param adGroupId The ID of the ad group that shall be retrieved.
|
|
191
|
+
* @param body This type defines the fields for the <b>UpdateAdGroup</b> request.
|
|
192
|
+
*/
|
|
193
|
+
updateAdGroup(campaignId: string, adGroupId: string, body: UpdateAdGroupRequest): Promise<any>;
|
|
194
|
+
/**
|
|
195
|
+
*
|
|
196
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
197
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
198
|
+
* @param adGroupId The ID of the ad group that shall be retrieved.
|
|
199
|
+
* @param body The data requested to retrieve the suggested bids.
|
|
200
|
+
*/
|
|
201
|
+
suggestBids(campaignId: string, adGroupId: string, body: TargetedBidRequest): Promise<any>;
|
|
202
|
+
/**
|
|
203
|
+
*
|
|
204
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
205
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
206
|
+
* @param adGroupId The ID of the ad group that shall be retrieved.
|
|
207
|
+
* @param body The required data to retrieve suggested keywords.
|
|
208
|
+
*/
|
|
209
|
+
suggestKeywords(campaignId: string, adGroupId: string, body: TargetedKeywordRequest): Promise<any>;
|
|
143
210
|
/**
|
|
144
211
|
* This method clones (makes a copy of) the specified campaign.
|
|
145
212
|
*
|
|
@@ -236,6 +303,30 @@ export default class Marketing extends Restful {
|
|
|
236
303
|
* a seller's campaign IDs by calling getCampaigns.
|
|
237
304
|
*/
|
|
238
305
|
resumeCampaign(campaignId: string): Promise<any>;
|
|
306
|
+
/**
|
|
307
|
+
*
|
|
308
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that is generated when a campaign is created.
|
|
309
|
+
* @param categoryIds Specifies the category ID that is used to limit the results.
|
|
310
|
+
* @param limit Specifies the maximum number of campaigns to return on a page in the paginated response.
|
|
311
|
+
* @param offset Specifies the number of campaigns to skip in the result set before returning the first report in the paginated response.
|
|
312
|
+
*/
|
|
313
|
+
suggestItems(campaignId: string, { categoryIds, limit, offset }?: {
|
|
314
|
+
categoryIds?: string;
|
|
315
|
+
limit?: number;
|
|
316
|
+
offset?: number;
|
|
317
|
+
}): Promise<any>;
|
|
318
|
+
/**
|
|
319
|
+
*
|
|
320
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that is generated when a campaign is created.
|
|
321
|
+
* @param body This type defines the request fields for the ad rate strategy that shall be updated.
|
|
322
|
+
*/
|
|
323
|
+
updateAdRateStrategy(campaignId: string, body: UpdateAdrateStrategyRequest): Promise<any>;
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that is generated when a campaign is created.
|
|
327
|
+
* @param body This type defines the request fields for the budget details that shall be updated.
|
|
328
|
+
*/
|
|
329
|
+
updateCampaignBudget(campaignId: string, body: UpdateCampaignBudgetRequest): Promise<any>;
|
|
239
330
|
/**
|
|
240
331
|
* This method replaces the name and the start and end dates of a campaign.
|
|
241
332
|
*
|
|
@@ -244,6 +335,98 @@ export default class Marketing extends Restful {
|
|
|
244
335
|
* @param body This type defines the fields to updated the campaign name and start and end dates.
|
|
245
336
|
*/
|
|
246
337
|
updateCampaignIdentification(campaignId: string, body: UpdateCampaignIdentificationRequest): Promise<any>;
|
|
338
|
+
/**
|
|
339
|
+
*
|
|
340
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
341
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
342
|
+
* @param body A type that defines the fields for the bulk request to create keywords.
|
|
343
|
+
*/
|
|
344
|
+
bulkCreateKeyword(campaignId: string, body: BulkCreateKeywordRequest): Promise<any>;
|
|
345
|
+
/**
|
|
346
|
+
*
|
|
347
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
348
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
349
|
+
* @param body A type that defines the fields for the bulk request to update keywords.
|
|
350
|
+
*/
|
|
351
|
+
bulkUpdateKeyword(campaignId: string, body: BulkUpdateKeywordRequest): Promise<any>;
|
|
352
|
+
/**
|
|
353
|
+
*
|
|
354
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
355
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
356
|
+
* @param adGroupIds A comma-separated list of ad group IDs.
|
|
357
|
+
* @param keywordStatus A comma-separated list of keyword statuses.
|
|
358
|
+
* @param limit Specifies the maximum number of results to return on a page in the paginated response.
|
|
359
|
+
* @param offset Specifies the number of results to skip in the result set before returning the first report in the paginated response.
|
|
360
|
+
*/
|
|
361
|
+
getKeywords(campaignId: string, { adGroupIds, keywordStatus, limit, offset }?: {
|
|
362
|
+
adGroupIds?: string;
|
|
363
|
+
keywordStatus?: string;
|
|
364
|
+
limit?: number;
|
|
365
|
+
offset?: number;
|
|
366
|
+
}): Promise<any>;
|
|
367
|
+
/**
|
|
368
|
+
*
|
|
369
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
370
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
371
|
+
* @param body A type that defines the fields for the request to create a keyword.
|
|
372
|
+
*/
|
|
373
|
+
createKeyword(campaignId: string, body: CreateKeywordRequest): Promise<any>;
|
|
374
|
+
/**
|
|
375
|
+
*
|
|
376
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
377
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
378
|
+
* @param keywordId This path parameter is used to identify the keyword to retrieve.
|
|
379
|
+
*/
|
|
380
|
+
getKeyword(campaignId: string, keywordId: string): Promise<any>;
|
|
381
|
+
/**
|
|
382
|
+
*
|
|
383
|
+
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
|
|
384
|
+
* a seller's campaign IDs by calling getCampaigns.
|
|
385
|
+
* @param keywordId This path parameter is used to identify the keyword to retrieve.
|
|
386
|
+
* @param body A type that defines the fields for the request to update a keyword.
|
|
387
|
+
*/
|
|
388
|
+
updateKeyword(campaignId: string, keywordId: string, body: UpdateKeywordRequest): Promise<any>;
|
|
389
|
+
/**
|
|
390
|
+
*
|
|
391
|
+
* @param body A type that defines the fields for the bulk request to create negative keywords.
|
|
392
|
+
*/
|
|
393
|
+
bulkCreateNegativeKeyword(body: BulkCreateNegativeKeywordRequest): Promise<any>;
|
|
394
|
+
/**
|
|
395
|
+
*
|
|
396
|
+
* @param body A type that defines the fields for the bulk request to create negative keywords.
|
|
397
|
+
*/
|
|
398
|
+
bulkUpdateNegativeKeyword(body: BulkUpdateNegativeKeywordRequest): Promise<any>;
|
|
399
|
+
/**
|
|
400
|
+
*
|
|
401
|
+
* @param adGroupIds A comma-separated list of ad group IDs.
|
|
402
|
+
* @param campaignIds A unique eBay-assigned ID for an ad campaign that is generated when a campaign is created.
|
|
403
|
+
* @param limit The number of results, from the current result set, to be returned in a single page.
|
|
404
|
+
* @param negativeKeywordStatus A comma-separated list of negative keyword statuses.
|
|
405
|
+
* @param offset The number of results that will be skipped in the result set.
|
|
406
|
+
*/
|
|
407
|
+
getNegativeKeywords({ adGroupIds, campaignIds, limit, negativeKeywordStatus, offset }?: {
|
|
408
|
+
adGroupIds?: string;
|
|
409
|
+
campaignIds?: string;
|
|
410
|
+
limit?: number;
|
|
411
|
+
negativeKeywordStatus?: string;
|
|
412
|
+
offset?: number;
|
|
413
|
+
}): Promise<any>;
|
|
414
|
+
/**
|
|
415
|
+
*
|
|
416
|
+
* @param body A type that defines the fields for the request to create a negative keyword.
|
|
417
|
+
*/
|
|
418
|
+
createNegativeKeyword(body: CreateNegativeKeywordRequest): Promise<any>;
|
|
419
|
+
/**
|
|
420
|
+
*
|
|
421
|
+
* @param negativeKeywordId The unique identifier for the negative keyword.
|
|
422
|
+
*/
|
|
423
|
+
getNegativeKeyword(negativeKeywordId: string): Promise<any>;
|
|
424
|
+
/**
|
|
425
|
+
*
|
|
426
|
+
* @param negativeKeywordId The unique identifier for the negative keyword.
|
|
427
|
+
* @param body A type that defines the fields for the request to update a negative keyword.
|
|
428
|
+
*/
|
|
429
|
+
updateNegativeKeyword(negativeKeywordId: string, body: UpdateNegativeKeywordRequest): Promise<any>;
|
|
247
430
|
/**
|
|
248
431
|
* This call downloads the report as specified by the report_id path parameter.
|
|
249
432
|
*
|