eBay TypeScript/JavaScript API for Browser and Node
This eBay API implements both Traditional (xml) and the RESTful eBay API. It supports client credentials grant and authorization code grant (Auth'N'Auth, OAuth2 and IAF).

eBay Docs

Changelog

  • v7.0.2 is the latest release.
  • See here for the full changelog.

Implementation status

RESTful API

API
Implemented
Buy API
✔ Browse API v1.10.0 ✔ Deal API v1.3.0 ✔ Feed API ✔ Marketing API ✔ Offer API ✔ Order API ✔ Marketplace Insights API
Commerce API
✔ Catalog API ✔ Charity API v1.2.0 ✔ Identity API ✔ Notification API v1.2.0 ✔ Taxonomy API v1.0.0 ✔ Translation API v1_beta.1.4
Developer API
✔ Analytics API
Post Order API
✔ Cancellation API ✔ Case Management API ✔ Inquiry API ✔ Return API
Sell API
✔ Account API v1.6.3 ✔ Analytics API v1.3.0 ✔ Compliance API v1.4.1 ✔ Feed API ✔ Finance API v1.9.0 ✔ Fulfillment API v1.19.10 ✔ Inventory API v1.14.0 ✔ Listing API ✔ Logistics API ✔ Marketing API v1.10.0 ✔ Metadata API ✔ Negotiation API v1.1.0 ✔ Recommendation API v1.1.0

Traditional API

API
Implemented
Finding API
Shopping API
Merchandising API
Trading API
Client Alerts API
Feedback API

Install

1
npm install ebay-api
2
yarn add ebay-api
Copied!

🚀 Usage & Quick start

Sign up for an API key here: Developer Account. Checkout API examples.

NodeJS

1
import eBayApi from 'ebay-api';
2
// or:
3
// const eBayApi = require('ebay-api')
4
5
const eBay = new eBayApi({
6
appId: '-- also called Client ID --',
7
certId: '-- also called Client Secret --',
8
sandbox: false
9
});
10
11
const item = await eBay.buy.browse.getItem('v1|254188828753|0');
12
console.log(JSON.stringify(item, null, 2));
Copied!

Detailed configuration example

1
import eBayApi from 'ebay-api';
2
3
const eBay = new eBayApi({
4
appId: '-- also called Client ID --',
5
certId: '-- also called Client Secret --',
6
sandbox: false,
7
8
siteId: eBayApi.SiteId.EBAY_US, // required for traditional APIs, see https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html
9
10
marketplaceId: eBayApi.MarketplaceId.EBAY_US, // defautl. required for RESTful APIs
11
acceptLanguage: eBayApi.Locale.en_US, // defautl
12
contentLanguage: eBayApi.ContentLanguage.en_US, // defautl.
13
14
// optional parameters, should be omitted if not used
15
devId: '-- devId --', // required for traditional Trading API
16
ruName: '-- eBay Redirect URL name --', // 'RuName' (eBay Redirect URL name) required for authorization code grant
17
18
authToken: '-- Auth\'n\'Auth for traditional API (used by trading) --', // can be set to use traditional API without code grant
19
});
Copied!

Browser

Check out live example: https://hendt.github.io/ebay-api/. Because of the eBay CORS problems a Proxy server is required to use the API in the Browser.
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
Or use [https://github.com/Rob--W/cors-anywhere](CORS Anywhere is a NodeJS proxy) (works very well with heroku.com).
1
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/lib/ebay-api.min.js"></script>
2
<script>
3
const eBay = new eBayApi({
4
appId: 'appId',
5
certId: 'certId',
6
sandbox: false
7
});
8
9
// eBay.req.instance is AxiosInstance per default
10
eBay.req.instance.interceptors.request.use((request) => {
11
// Add Proxy
12
request.url = 'https://ebay.hendt.workers.dev/' + request.url;
13
return request;
14
});
15
16
eBay.buy.browse.getItem('v1|254188828753|0').then(item => {
17
console.log(JSON.stringify(item, null, 2));
18
}).catch(e => {
19
console.error(e);
20
});
21
</script>
Copied!

🔧 eBayApi Config

The first (required) parameter in eBayApi instance takes an object with following properties:
Name
Occurrence
Description
appId
Required
App ID (Client ID) from Application Keys.
certId
Required
Cert ID (Client Secret) from Application Keys.
devId
Conditionally
The Dev Id from Application Keys.
sandbox
Required
1
Default: false
Copied!
If true, the Sandbox Environment will be used.
ruName
Conditionally
The redirect_url value. More info.
autoRefreshToken
Required
1
Default: true
Copied!
Auto refresh the token if it's expired.
siteId Traditional
Required
1
Default: SiteId.EBAY_US
Copied!
eBay site to which you want to send the request (Trading API, Shopping API).
authToken Traditional
Optional
The Auth'N'Auth token. The traditional authentication and authorization technology used by the eBay APIs.
marketplaceId RESTful
Required
1
Default: MarketplaceId.EBAY_US
Copied!
Docs 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.
scope RESTful
Conditionally
1
Default:['https://api.ebay.com/oauth/api_scope']
Copied!
The scopes assigned to your application allow access to different API resources and functionality.
endUserCtx RESTful
Conditionally recommended RESTful
Docs X-EBAY_C_ENDUSERCTX provides various types of information associated with the request.
contentLanguage RESTful
Conditionally required
1
Default: ContentLanguage.en_US
Copied!
DocsContent-Language indicates the locale preferred by the client for the response.
acceptLanguage RESTful
Optional
1
Default: Locale.en_US
Copied!
Docs 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.

Load config from environment

Use eBayApi.fromEnv() to load data from environment variables.
Name
Value
appId
process.env.EBAY_APP_ID
certId
process.env.EBAY_CERT_ID
devId
process.env.EBAY_DEV_ID
authToken
process.env.EBAY_AUTH_TOKEN
siteId
process.env.EBAY_SITE_ID
marketplaceId
process.env.EBAY_MARKETPLACE_ID
ruName
process.env.EBAY_RU_NAME
sandbox
process.env.EBAY_SANDBOX === 'true'

🐞 Debug

To see node debug logs use DEBUG=ebay:* environment variable.

🔑 Access token types

See the full Documentation here.
Client credentials grant flow mints a new Application access token. Authorization code grant flow mints a new User access token.

User access token (authorization code grant flow)

👉 Recommended for all API Calls.
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). 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).

Application access token (client credentials grant flow)

👉 Recommended for API calls that will only request application data (GET method, and it's also restricted).
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. (eBay Token Types)
If no other token is set, this token will be obtained automatically in the process of calling an RESTful API.

Auth'N'Auth

👉 The "old" way. Only works with Traditional API. Checkout the Auth'N'Auth example.
You can also generate the token on eBay developer page and use it directly (see Detailed configuration example).

OAuth2: Exchanging the authorization code for a User access token

eBay Docs
1
import eBayApi from 'ebay-api';
2
3
// 1. Create new eBayApi instance and set the scope.
4
const eBay = eBayApi.fromEnv();
5
6
eBay.OAuth2.setScope([
7
'https://api.ebay.com/oauth/api_scope',
8
'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
9
'https://api.ebay.com/oauth/api_scope/sell.fulfillment'
10
]);
11
12
// 2. Generate and open Url and Grant Access
13
const url = eBay.OAuth2.generateAuthUrl();
14
console.log('Open URL', url);
Copied!
After you granted success, eBay will redirect you to your 'Auth accepted URL' and add a query parameter code

Express example

This is how it would look like if you use express:
1
import eBayApi from 'ebay-api';
2
3
app.get('/success', async function(req, res) {
4
// 3. Get the parameter code that is placed as query parameter in redirected page
5
const code = req.query.code; // this is provided from eBay
6
const eBay = eBayApi.fromEnv(); // or use new eBayApi()
7
8
try {
9
const token = await eBay.OAuth2.getToken(code);
10
eBay.OAuth2.setCredentials(token);
11
// store this token e.g. to a session
12
req.session.token = token
13
14
// 5. Start using the API
15
const orders = await eBay.sell.fulfillment.getOrders()
16
res.send(orders);
17
} catch(e) {
18
console.error(e)
19
res.sendStatus(400)
20
}
21
});
Copied!
If token is already in session:
1
import eBayApi from 'ebay-api';
2
3
app.get('/orders/:id', async function(req, res) {
4
const id = req.params.id;
5
const eBay = eBayApi.fromEnv(); // or use new eBayApi(...)
6
const token = req.session.token;
7
if (!token) {
8
return res.sendStatus(403);
9
}
10
11
eBay.OAuth2.setCredentials(token);
12
13
// If token get's refreshed
14
eBay.OAuth2.on('refreshAuthToken', (token) => {
15
req.session.token = token;
16
});
17
18
try {
19
// 5. Start using the API
20
const order = await eBay.sell.fulfillment.getOrder(id);
21
res.send(order);
22
} catch(e) {
23
console.error(e)
24
res.sendStatus(400)
25
}
26
});
Copied!

RESTful API

How to set the Scope

1
const eBay = new eBayApi({
2
// ...
3
scope: ['https://api.ebay.com/oauth/api_scope']
4
});
5
6
// Or:
7
eBay.OAuth2.setScope([
8
'https://api.ebay.com/oauth/api_scope',
9
'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
10
'https://api.ebay.com/oauth/api_scope/sell.fulfillment'
11
]);
Copied!

Use apix.ebay.com or apiz.ebay.com (beta) endpoints

For some APIs, eBay use a apix/apiz subdomain. To use these subdomains you can use .apix/.apiz before the api call like this:
1
eBay.buy.browse.apix.getItem() // now it will use https://apix.ebay.com
2
eBay.buy.browse.apiz.getItem() // now it will use https://apiz.ebay.com
Copied!
In any case eBay adds a new subdomain, it's also possible to configure whatever you want:
1
eBay.buy.browse.api({subdomain: 'apiy'}).getItem() // now it will use https://apiy.ebay.com
Copied!

Change RESTful API call config

1
eBay.buy.browse.api({
2
returnResponse: true, // return the response instead of data
3
}).getItem();
Copied!

How to refresh the token

If autoRefreshToken is set to true (default value) the token will be automatically refreshed when eBay response with invalid access token error.
Use Event Emitter to get the token when it gets successfully refreshed.
1
eBay.OAuth2.on('refreshAuthToken', (token) => {
2
console.log(token)
3
// Store this token in DB
4
});
5
6
// for client token
7
eBay.OAuth2.on('refreshClientToken', (token) => {
8
console.log(token)
9
// Store this token in DB
10
});
Copied!
To manuel refresh the auth token use eBay.OAuth2.refreshAuthToken() and for the client token eBay.OAuth2.refreshClientToken(). Keep in mind that you need the 'refresh_token' value set.
1
const token = await eBay.OAuth2.refreshToken();
2
// will refresh Auth Token if set, otherwise the client token if set.
Copied!

Additional request headers

Sometimes you want to add additional headers to the request like a GLOBAL-ID X-EBAY-SOA-GLOBAL-ID. You have multiple options to do this.

RESTful API headers

1
const eBay = new eBayApi();
2
3
eBay.buy.browse.api({headers: {
4
'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
5
}}).getItem('v1|382282567190|651094235351').then((item) => {
6
console.log(item)
7
})
Copied!

Traditional API headers

You can pass headers directly in the method call in the second parameter:
1
eBay.trading.AddFixedPriceItem({
2
Item: {
3
Title: 'title',
4
Description: {
5
__cdata: '<div>test</div>'
6
}
7
}
8
}, {
9
headers: {
10
'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
11
}
12
})
Copied!

Low level: use the Axios interceptor to manipulate the request

1
import eBayApi from 'ebay-api';
2
const eBay = new eBayApi(/* { your config here } */);
3
4
eBay.req.instance.interceptors.request.use((request) => {
5
// Add Header
6
request.headers['X-EBAY-SOA-GLOBAL-ID'] = 'EBAY-DE';
7
return request;
8
})
Copied!

Handle JSON GZIP response e.g fetchItemAspects

You need a decompress library installed like zlib.
1
npm install zlib # or yarn add zlib
Copied!
1
import eBayApi from 'ebay-api';
2
import zlib from 'zlib';
3
4
const toString = (data) => new Promise((resolve) => {
5
zlib.gunzip(data, (err, output) => {
6
if (err) throw err;
7
resolve(output.toString());
8
});
9
});
10
11
const eBay = new eBayApi(/* { your config here } */);
12
13
try {
14
const data = await eBay.commerce.taxonomy.fetchItemAspects(/* categoryTreeId */);
15
const result = await toString(data);
16
17
console.log(result)
18
} catch (e) {
19
console.error(e);
20
}
Copied!

Controlling Traditional XML request and response

The second parameter in the traditional API has the following options:
1
export type Options = {
2
raw?: boolean // return raw XML
3
parseOptions?: object // https://github.com/NaturalIntelligence/fast-xml-parser
4
useIaf?: boolean // use IAF in header instead of Bearer
5
headers?: Headers // additional Headers (key, value)
6
hook?: (xml) => BodyHeaders // hook into the request to modify the body and headers
7
};
Copied!
Fast XML is used to parse the XML. You can pass the parse option to parseOptions parameter.

Examples

Trading - AddFixedPriceItem (CDATA)

You can submit your description using CDATA if you want to use HTML or XML.
1
eBay.trading.AddFixedPriceItem({
2
Item: {
3
Title: 'title',
4
Description: {
5
__cdata: '<div>test</div>'
6
}
7
}
8
})
Copied!

Trading - ReviseFixedPriceItem (Update the price of an item)

1
eBay.trading.ReviseFixedPriceItem({
2
Item: {
3
ItemID: 'itemId',
4
StartPrice: 'startPrice'
5
}
6
})
Copied!

Buy - getItem

1
eBay.buy.browse.getItem('v1|382282567190|651094235351').then(a => {
2
console.log(a);
3
}).catch(e => {
4
console.log(e)
5
});
Copied!

Post-Order - getReturn

1
eBay.postOrder.return.getReturn('5132021997').then(a => {
2
console.log(a);
3
}).catch(e => {
4
console.log(e)
5
});
Copied!

Finding - findItemsByProduct (use XML attributes and value)

1
eBay.finding.findItemsByProduct({
2
productId: {
3
'@_type': 'ReferenceID',
4
'#value': '53039031'
5
}
6
})
7
8
// will produce:
9
// <productId type="ReferenceID">53039031</productId>
Copied!

Finding - findItemsIneBayStores

1
eBay.finding.findItemsIneBayStores({
2
storeName: 'HENDT'
3
}, {raw: true}).then(result => {
4
// Return raw XML
5
console.log(result);
6
});
Copied!

Finding - findItemsAdvanced (findItemsByKeywords)

1
eBay.finding.findItemsAdvanced({
2
itemFilter: [{
3
name: 'Seller',
4
value: 'hendt_de'
5
}],
6
keywords: 'katze'
7
}).then(result => {
8
console.log(result);
9
});
Copied!

Trading - GetMyeBaySelling

1
eBay.trading.GetMyeBaySelling({
2
SoldList: {
3
Include: true,
4
Pagination: {
5
EntriesPerPage: 20,
6
PageNumber: 1
7
}
8
}
9
}).then(data => {
10
console.log(data.results)
11
});
Copied!

FAQ

  1. 1.
    Do I need the eBay OAuth Client dependency?
No. This library has already all authentication implemented and support also auto refreshing token.
  1. 1.
    What does IAF mean?
IAF stands for IDENTITY ASSERTION FRAMEWORK. The traditional API supports IAF. That means you can use the OAuth2 token with the traditional APIs.
  1. 1.
    Is it possible to Upload Pictures directly to EPS?
Yes. Checkout the Browser example and Node Example here.

Contribution

Check here

Supported By

📝 License

MIT.
Last modified 1d ago