# eBay TypeScript/JavaScript API for Browser and Node

[![codecov](https://codecov.io/gh/hendt/ebay-api/branch/master/graph/badge.svg?token=E67PSWIZFZ)](https://codecov.io/gh/hendt/ebay-api)

[![npm version](https://img.shields.io/npm/v/ebay-api.svg?style=flat-square)](https://www.npmjs.com/package/ebay-api) [![npm downloads](https://img.shields.io/npm/dt/ebay-api.svg?style=flat-square)](https://www.npmjs.com/package/ebay-api) [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/ebay-api/badge)](https://www.jsdelivr.com/package/npm/ebay-api)

[![License](https://img.shields.io/npm/l/ebay-api?style=flat-square)](https://github.com/hendt/ebay-api/blob/master/LICENSE/README.md)

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). Digital Signature is supported too.

* [API Browser Examples](https://hendt.github.io/ebay-api/)
* [API Documentation](https://hendt.gitbook.io/ebay-api/)

## Table of Contents

* [🚀 Quick Start](#-quick-start)
* [Install](#install)
* [eBay Docs](#ebay-docs)
* [Implementation Status](#implementation-status)
* [🔧 eBayApi Config](#-ebayapi-config)
* [Load Config from Environment](#load-config-from-environment)
* [🐞 Debug](#-debug)
* [🔑 Access Token Types](#-access-token-types)
* [OAuth2: Authorization Code Grant](#oauth2-exchanging-the-authorization-code-for-a-user-access-token)
* [Digital Signature](#digital-signature)
* [RESTful API](#restful-api)
* [Traditional API](#controlling-traditional-xml-request-and-response)
* [Examples](#examples)
* [FAQ](#faq)
* [Contribution](#contribution)
* [📝 License](#-license)

## 🚀 Quick Start

Sign up for an API key here: [Developer Account](https://developer.ebay.com/signin?tab=register).

### Installation

```bash
npm install ebay-api 
# or
yarn add ebay-api
```

### Basic Usage

```typescript
import eBayApi from 'ebay-api';
// or:
// const eBayApi = require('ebay-api')

const eBay = new eBayApi({
  appId: '-- also called Client ID --',
  certId: '-- also called Client Secret --',
  sandbox: false
});

const item = await eBay.buy.browse.getItem('v1|254188828753|0');
console.log(JSON.stringify(item, null, 2));
```

For more examples, check out the [examples directory](https://github.com/hendt/ebay-api/blob/master/examples/README.md).

## eBay Docs

* [eBay API Explorer](https://developer.ebay.com/my/api_test_tool)
* [eBay API Docs](https://developer.ebay.com/docs)
* [eBay API Status](https://entwickler.ebay.de/support/api-status/production)

## Changelog

* `v9.5.1` is the latest release.
* See [here](https://github.com/hendt/ebay-api/blob/master/CHANGELOG.md) for the full changelog.

## Implementation status

### RESTful API

| API                | Implemented                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Buy API**        | <p>✔ Browse API <code>v1.10.0</code><br>✔ Deal API <code>v1.3.0</code><br>✔ Feed API <code>v1.3.1</code><br>✔ Marketing API <code>v1\_beta.1.0</code><br>✔ Offer API <code>v1\_beta.0.0</code><br>✔ Order API <code>v1\_beta.20.0</code><br>✔ Marketplace Insights API <code>v1\_beta.2.2</code></p>                                                                                                                                                                                                                                         |
| **Commerce API**   | <p>✔ Catalog API <code>v1\_beta.3.1</code><br>✔ Charity API <code>v1.2.0</code><br>✔ Identity API <code>v1.0.0</code><br>✔ Notification API <code>v1.2.0</code><br>✔ Taxonomy API <code>v1.0.0</code><br>✔ Translation API <code>v1\_beta.1.4</code><br>✔ Media API <code>v1\_beta.1.0</code><br>✔ Message API <code>v1.0.0</code></p>                                                                                                                                                                                                       |
| **Developer API**  | ✔ Analytics API                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| **Post Order API** | <p>✔ Cancellation API<br>✔ Case Management API<br>✔ Inquiry API<br>✔ Return API</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| **Sell API**       | <p>✔ Account API <code>v1.9.0</code><br>✔ Analytics API <code>v1.3.0</code><br>✔ Compliance API <code>v1.4.1</code><br>✔ Feed API <code>v1.3.1</code><br>✔ Finance API <code>v1.9.0</code><br>✔ Fulfillment API <code>v1.19.10</code><br>✔ Inventory API <code>v1.18.0</code><br>✔ Listing API <code>v1\_beta.2.1</code><br>✔ Logistics API <code>v1\_beta.0.0</code><br>✔ Marketing API <code>v1.17.0</code><br>✔ Metadata API <code>v1.7.1</code><br>✔ Negotiation API <code>v1.1.0</code><br>✔ Recommendation API <code>v1.1.0</code></p> |

### Traditional API

| API                   | Implemented |
| --------------------- | ----------- |
| **Shopping API**      | ✔           |
| **Merchandising API** | ✔           |
| **Trading API**       | ✔           |
| **Client Alerts API** | ✔           |
| **Feedback API**      | ✔           |

## Detailed Configuration

```typescript
import eBayApi from 'ebay-api';

const eBay = new eBayApi({
  appId: '-- also called Client ID --',
  certId: '-- also called Client Secret --',
  sandbox: false,

  siteId: eBayApi.SiteId.EBAY_US, // required for traditional APIs, see https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html

  marketplaceId: eBayApi.MarketplaceId.EBAY_US, // default. required for RESTful APIs
  acceptLanguage: eBayApi.Locale.en_US, // default
  contentLanguage: eBayApi.Locale.en_US, // default.

  // optional parameters, should be omitted if not used
  devId: '-- devId --', // required for traditional Trading API
  ruName: '-- eBay Redirect URL name --', // 'RuName' (eBay Redirect URL name) required for authorization code grant

  authToken: '--  Auth\'n\'Auth for traditional API (used by trading) --', // can be set to use traditional API without code grant
});
```

## Browser Usage

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 purposes you can use `https://ebay.hendt.workers.dev/` url as proxy. You can also set up your own Proxy server. We have added an example for cloudfront workers: <https://github.com/hendt/ebay-api/blob/master/proxy/worker.js>

Or use [CORS Anywhere](https://github.com/Rob--W/cors-anywhere) (a NodeJS proxy that works very well with heroku.com).

#### ESM

```html

<script type="module">
    import eBayApi from 'https://cdn.jsdelivr.net/npm/ebay-api@latest/dist/ebay-api.min.mjs';
    // or 
    import eBayApiEsm from 'https://esm.sh/ebay-api';
</script>
```

#### UMD

```html

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ebay-api@latest/lib/ebay-api.min.js"></script>
<script>
    const eBay = new eBayApi({
        appId: 'appId',
        certId: 'certId',
        sandbox: false
    });

    // eBay.req.instance is AxiosInstance per default
    eBay.req.instance.interceptors.request.use((request) => {
        // Add Proxy
        request.url = 'https://ebay.hendt.workers.dev/' + request.url;
        return request;
    });

    eBay.buy.browse.getItem('v1|254188828753|0').then(item => {
        console.log(JSON.stringify(item, null, 2));
    }).catch(e => {
        console.error(e);
    });
</script>
```

## 🔧 eBayApi Config

The first (required) parameter in eBayApi instance takes an object with following properties:

<table><thead><tr><th>Name</th><th>Occurrence</th><th>Description</th></tr></thead><tbody><tr><td>appId</td><td>Required</td><td>App ID (Client ID) from <a href="https://developer.ebay.com/my/keys">Application Keys</a>.</td></tr><tr><td>certId</td><td>Required</td><td>Cert ID (Client Secret) from <a href="https://developer.ebay.com/my/keys">Application Keys</a>.</td></tr><tr><td>devId</td><td>Conditionally</td><td>The Dev Id from <a href="https://developer.ebay.com/my/keys">Application Keys</a>.</td></tr><tr><td>sandbox</td><td><p>Required<br></p><pre><code>Default: false
</code></pre></td><td>If true, the <a href="https://developer.ebay.com/tools/sandbox">Sandbox Environment</a> will be used.</td></tr><tr><td>ruName</td><td>Conditionally</td><td>The redirect_url value. <a href="https://developer.ebay.com/api-docs/static/oauth-redirect-uri.html">More info</a>.</td></tr><tr><td>autoRefreshToken</td><td><p>Required</p><pre><code>Default: true
</code></pre></td><td>Auto refresh the token if it's expired.</td></tr><tr><td>siteId<br><em>Traditional</em></td><td><p>Required<br></p><pre><code>Default: SiteId.EBAY_US
</code></pre></td><td>eBay site to which you want to send the request (Trading API, Shopping API).</td></tr><tr><td>authToken<br><em>Traditional</em></td><td>Optional</td><td>The Auth'N'Auth token. The traditional authentication and authorization technology used by the eBay APIs.</td></tr><tr><td>parseOptions<br><em>Traditional</em></td><td><p>Optional<br></p><pre><code>Default: { processEntities: { maxTotalExpansions: 10000 } }
</code></pre></td><td>Global <a href="https://github.com/NaturalIntelligence/fast-xml-parser">fast-xml-parser</a> parse options applied to all Traditional API responses. Can be overridden per-call.</td></tr><tr><td>marketplaceId<br><em>RESTful</em></td><td><p>Required<br></p><pre><code>Default: MarketplaceId.EBAY_US
</code></pre></td><td><a href="https://developer.ebay.com/api-docs/static/rest-request-components.html#marketpl">Docs</a> 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.</td></tr><tr><td>scope<br><em>RESTful</em></td><td><p>Conditionally</p><pre><code>Default:
['https://api.ebay.com/oauth/api_scope'] 
</code></pre></td><td>The scopes assigned to your application allow access to different API resources and functionality.</td></tr><tr><td>endUserCtx<br><em>RESTful</em></td><td>Conditionally recommended<br><em>RESTful</em></td><td><a href="https://developer.ebay.com/api-docs/static/rest-request-components.html#headers">Docs</a> X-EBAY_C_ENDUSERCTX provides various types of information associated with the request.</td></tr><tr><td>contentLanguage<br><em>RESTful</em></td><td><p>Conditionally required<br></p><pre><code>Default: Locale.en_US
</code></pre></td><td><a href="https://developer.ebay.com/api-docs/static/rest-request-components.html#headers">Docs</a>Content-Language indicates the locale preferred by the client for the response.</td></tr><tr><td>acceptLanguage<br><em>RESTful</em></td><td><p>Optional</p><pre><code>Default: Locale.en_US
</code></pre></td><td><a href="https://developer.ebay.com/api-docs/static/rest-request-components.html#headers">Docs</a> 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.</td></tr></tbody></table>

## 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](https://developer.ebay.com/api-docs/static/oauth-token-types.html).

*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)](https://developer.ebay.com/api-docs/static/oauth-token-types.html).

### 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)](https://developer.ebay.com/api-docs/static/oauth-token-types.html)

If no other token is set, this token will be obtained *automatically* in the process of calling an RESTful API.

### Auth'N'Auth

In the Single User Model, the application supports only a single user. In this model, you need only one Auth'n'Auth token. 👉 The "old" way. Only works with Traditional API. Checkout the [Auth'N'Auth example](https://github.com/hendt/ebay-api/tree/master/examples/traditional/authNAuth.ts).

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](https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html)

```js
import eBayApi from 'ebay-api';

// 1. Create new eBayApi instance and set the scope.
const eBay = eBayApi.fromEnv();

eBay.OAuth2.setScope([
  'https://api.ebay.com/oauth/api_scope',
  'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
  'https://api.ebay.com/oauth/api_scope/sell.fulfillment'
]);

// 2. Generate and open Url and Grant Access
const url = eBay.OAuth2.generateAuthUrl();
console.log('Open URL', url);
```

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`:

```js
import eBayApi from 'ebay-api';


// This is your RUName endpoint like https://your-ebay.app/success
app.get('/success', async function (req, res) {
  // 3. Get the parameter code that is placed as query parameter in redirected page
  const code = req.query.code; // this is provided from eBay
  const eBay = eBayApi.fromEnv(); // or use new eBayApi()

  try {
    const token = await eBay.OAuth2.getToken(code);
    eBay.OAuth2.setCredentials(token);
    // store this token e.g. to a session
    req.session.token = token

    // 5. Start using the API
    const orders = await eBay.sell.fulfillment.getOrders()
    res.send(orders);
  } catch (error) {
    console.error(error)
    res.sendStatus(400)
  }
});
```

If token is already in session:

```js
import eBayApi from 'ebay-api';

app.get('/orders/:id', async function (req, res) {
  const id = req.params.id;
  const eBay = eBayApi.fromEnv(); // or use new eBayApi(...)
  const token = req.session.token;
  if (!token) {
    return res.sendStatus(403);
  }

  eBay.OAuth2.setCredentials(token);

  // If token get's refreshed
  eBay.OAuth2.on('refreshAuthToken', (token) => {
    req.session.token = token;
  });

  try {
    // 5. Start using the API
    const order = await eBay.sell.fulfillment.getOrder(id);
    res.send(order);
  } catch (error) {
    console.error(error)
    res.sendStatus(400)
  }
});
```

## Digital Signature

Signatures are required when the call is made for EU- or UK-domiciled sellers, and only for the following APIs/methods:

* All methods in the Finances API -> (`eBay.finances.XXX.sign.YYY()`)
* issueRefund in the Fulfillment API -> (`eBay.sell.fulfillment.sign.issueRefund()`)
* GetAccount in the Trading API -> (`eBay.trading.GetAccount(null, { sign: true }))`)
* The following methods in the Post-Order API:
  * Issue Inquiry Refund -> (`eBay.postOrder.inquiry.sign.issueInquiryRefund()`)
  * Issue case refund -> (`eBay.postOrder.inquiry.sign.issueCaseRefund()`)
  * Issue return refund -> (`eBay.postOrder.inquiry.sign.issueReturnRefund()`)
  * Process Return Request -> (`eBay.postOrder.inquiry.sign.processReturnRequest()`)
  * Create Cancellation Request -> (`eBay.postOrder.inquiry.sign.createCancellation()`)
  * Approve Cancellation Request -> (`eBay.postOrder.inquiry.sign.approveCancellationRequest()`)

### How to use Digital Signature

```typescript
// 1. Create signing key and save it appropriately
const signingKey = await eBay.developer.keyManagement.createSigningKey('ED25519');
// 2. Set the signature
eBay.setSignature(signingKey)
// or in constructor
eBay = new eBayApi({
   appId: '...',
   certId: '...',
   signature: {
      jwe: signingKey.jwe,
      privateKey: signingKey.privateKey
   }
});
// 3. Use the 'sign' keyword in Restful API
const summary = await eBay.sell.finances.sign.getSellerFundsSummary();
// 3. Or the 'sign' parameter in traditional API
const account = await eBay.trading.GetAccount(null, {sign: true});
```

## RESTful API

### How to set the Scope

```typescript
const eBay = new eBayApi({
  // ...
  scope: ['https://api.ebay.com/oauth/api_scope']
});

// Or:
eBay.OAuth2.setScope([
  'https://api.ebay.com/oauth/api_scope',
  'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
  'https://api.ebay.com/oauth/api_scope/sell.fulfillment'
]);
```

### 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:

```typescript
eBay.buy.browse.apix.getItem(); // now it will use https://apix.ebay.com
eBay.buy.browse.apiz.getItem(); // now it will use https://apiz.ebay.com
```

In any case eBay adds a new subdomain, it's also possible to configure whatever you want:

```typescript
eBay.buy.browse.api({subdomain: 'apiy'}).getItem(); // now it will use https://apiy.ebay.com
```

### Return raw RESTful API response

```typescript
eBay.buy.browse.api({
  returnResponse: true, // return the response instead of data
}).getItem();
```

### 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.

```typescript
eBay.OAuth2.on('refreshAuthToken', (token) => {
  console.log(token);
  // Store this token in DB
});

// for client token
eBay.OAuth2.on('refreshClientToken', (token) => {
  console.log(token)
  // Store this token in DB
});
```

To manual refresh the auth token use `eBay.OAuth2.refreshAuthToken()` and for the client token use `eBay.OAuth2.refreshClientToken()`. Keep in mind that you need the 'refresh\_token' value set.

```typescript
const token = await eBay.OAuth2.refreshToken();
// will refresh Auth Token if set, otherwise the client token if set.
```

## 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

```typescript
const eBay = new eBayApi();

eBay.buy.browse.api({
  headers: {
    'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
  }
}).getItem('v1|382282567190|651094235351').then((item) => {
  console.log(item);
});
```

### Traditional API headers

You can pass headers directly in the method call in the second parameter:

```typescript
eBay.trading.AddFixedPriceItem({
  Item: {
    Title: 'title',
    Description: {
      __cdata: '<div>test</div>'
    }
  }
}, {
  headers: {
    'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
  }
});
```

### Low level: use the Axios interceptor to manipulate the request

```typescript
import eBayApi from 'ebay-api';

const eBay = new eBayApi(/* {  your config here } */);

eBay.req.instance.interceptors.request.use((request) => {
  // Add Header
  request.headers['X-EBAY-SOA-GLOBAL-ID'] = 'EBAY-DE';
  return request;
});
```

### Handle JSON GZIP response e.g fetchItemAspects

You need a decompress library installed like `zlib`.

```bash
npm install zlib # or yarn add zlib
```

```typescript
import eBayApi from 'ebay-api';
import zlib from 'zlib';

const toString = (data: Buffer): Promise<string> => new Promise((resolve) => {
  zlib.gunzip(data, (err, output) => {
    if (err) throw err;
    resolve(output.toString());
  });
});

const eBay = new eBayApi(/* {  your config here } */);

try {
  const data = await eBay.commerce.taxonomy.fetchItemAspects(/* categoryTreeId */);
  const result = await toString(data);

  console.log(result)
} catch (error) {
  console.error(error);
}
```

## Handling errors

```typescript
import eBayApi from 'ebay-api';
import { EBayApiError } from 'ebay-api/lib/errors';

const eBay = new eBayApi(/* {  your config here } */);

try {
  const result = await eBay.trading.GetItem({
    ItemID: 'itemId',
  });
  console.log(result);
} catch (error) {
  if (error instanceof EBayApiError && error.errorCode === 17) {
    // Item not found
  } else {
    throw error;
  }
  
  // in error there is also the field "meta" with the response
  if (error instanceof EBayApiError && error.meta?.res?.status === 404) {
    // not found
    
    // The first error
    console.log(error?.firstError);
  }
  
  
}
```

The `errorCode` is extracted from the first error in the API response.

* [Shopping API Error Codes](https://developer.ebay.com/devzone/shopping/docs/callref/Errors/ErrorMessages.html)
* [Trading API Error Codes](https://developer.ebay.com/devzone/xml/docs/reference/ebay/errors/errormessages.htm)
* [RESTful Error Codes](https://developer.ebay.com/devzone/xml/docs/reference/ebay/errors/errormessages.htm)
* [PostOrder Error Codes](https://developer.ebay.com/Devzone/post-order/ErrorMessages.html#ErrorsByNumber)

## Controlling Traditional XML request and response

### Global parse options (constructor)

Pass `parseOptions` in the constructor config to apply [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) options to **all** Traditional API responses:

```typescript
const eBay = new eBayApi({
  appId: '...',
  certId: '...',
  devId: '...',
  siteId: eBayApi.SiteId.EBAY_DE,
  parseOptions: {
    processEntities: {
      maxTotalExpansions: 20000 // raise limit for stores with rich HTML descriptions (default: 10000)
    }
  }
});
```

Per-call `parseOptions` (see below) are merged on top and take precedence.

### Per-call options

The second parameter in the traditional API has the following options:

```typescript
export type Options = {
  raw?: boolean // return raw XML
  parseOptions?: X2jOptions // https://github.com/NaturalIntelligence/fast-xml-parser — merged with global parseOptions
  xmlBuilderOptions?: XmlBuilderOptions // https://github.com/NaturalIntelligence/fast-xml-parser
  useIaf?: boolean // use IAF in header instead of Bearer
  headers?: Headers // additional Headers (key, value)
  hook?: (xml) => BodyHeaders // hook into the request to modify the body and headers
};
```

[Fast XML](https://github.com/NaturalIntelligence/fast-xml-parser) is used to parse the XML. You can pass the parse option to `parseOptions` parameter.

### Parse JSON Array

```js

eBay.trading.SetNotificationPreferences({
  UserDeliveryPreferenceArray: [{
    NotificationEnable: {
      EventType: 'ItemListed',
      EventEnable: 'Enable',
    }
  }, {
    NotificationEnable: {
      EventType: 'ItemSold',
      EventEnable: 'Enable',
    },
  }],
}, { xmlBuilderOptions: { oneListGroup: true }})
```

Will produce:

```xml
<UserDeliveryPreferenceArray>
  <NotificationEnable>
    <EventType>ItemListed</EventType>
    <EventEnable>Enable</EventEnable>
  </NotificationEnable>
  <NotificationEnable>
    <EventType>ItemSold</EventType>
    <EventEnable>Enable</EventEnable>
  </NotificationEnable>
</UserDeliveryPreferenceArray>
```

## Examples

### Trading - AddFixedPriceItem (CDATA)

You can submit your description using CDATA if you want to use HTML or XML.

```js
eBay.trading.AddFixedPriceItem({
  Item: {
    Title: 'title',
    Description: {
      __cdata: '<div>test</div>'
    }
  }
});
```

### Trading - ReviseFixedPriceItem (Update the price of an item)

```js
eBay.trading.ReviseFixedPriceItem({
  Item: {
    ItemID: 'itemId',
    StartPrice: 'startPrice'
  }
});
```

### Buy - getItem

```js
eBay.buy.browse.getItem('v1|382282567190|651094235351').then(a => {
  console.log(a);
}).catch(e => {
  console.log(e);
});
```

### Post-Order - getReturn

```js
eBay.postOrder.return.getReturn('5132021997').then(a => {
  console.log(a);
}).catch(e => {
  console.log(e);
});
```

### Finding - findItemsByProduct (use XML attributes and value)

```js
eBay.finding.findItemsByProduct({
  productId: {
    '@_type': 'ReferenceID',
    '#value': '53039031'
  }
});

// will produce:
// <productId type="ReferenceID">53039031</productId>
```

### Finding - findItemsIneBayStores

```js
eBay.finding.findItemsIneBayStores({
  storeName: 'HENDT'
}, {raw: true}).then(result => {
  // Return raw XML
  console.log(result);
});
```

### Finding - findItemsAdvanced (findItemsByKeywords)

```js
eBay.finding.findItemsAdvanced({
  itemFilter: [{
    name: 'Seller',
    value: 'hendt_de'
  }],
  keywords: 'katze'
}).then(result => {
  console.log(result);
});
```

### Trading - GetMyeBaySelling

```js
eBay.trading.GetMyeBaySelling({
  SoldList: {
    Include: true,
    Pagination: {
      EntriesPerPage: 20,
      PageNumber: 1
    }
  }
}).then(data => {
  console.log(data.results)
});
```

## FAQ

1. Do I need the [eBay OAuth Client](https://www.npmjs.com/package/ebay-oauth-nodejs-client) dependency?

No. This library has already all authentication implemented and support also auto refreshing token.

2. 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.

3. Is it possible to Upload Pictures directly to EPS?

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).

4. itemAffiliateWebUrl is missing in eBay.buy.browse.search call You have to set `endUserCtx`.

## Contribution

Check [here](https://github.com/hendt/ebay-api/blob/master/CONTRIBUTING.md)

## Supported By

[leaderboarded.com](https://leaderboarded.com/)

[rootle.de](https://rootle.de)

## 📝 License

MIT.
