Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
eBayApi
✓ import eBayApi from 'ebay-api';
✗ import { eBayApi } from 'ebay-api';
`eBayApi` is the default export of the module. Attempting to import it as a named export will result in an undefined value or a runtime error.
Config
✓ import type { Config } from 'ebay-api';
✗ import { Config } from 'ebay-api';
When importing only types in TypeScript, always use `import type` to ensure no runtime code is generated, preventing potential import errors or unnecessary bundle sizes.
eBayApi.fromEnv
✓ import eBayApi from 'ebay-api'; const eBay = eBayApi.fromEnv();
✗ import { fromEnv } from 'ebay-api';
`fromEnv` is a static method of the `eBayApi` class, designed to load configuration from environment variables. It should be called directly on the imported default `eBayApi` class, not imported as a standalone named export.
This quickstart demonstrates how to initialize the eBay API client using environment variables for credentials and fetch details for a specific item using the Buy Browse API, including error handling.
import eBayApi from 'ebay-api';
import 'dotenv/config'; // Optional: for loading .env variables
// Ensure your eBay Developer credentials are set as environment variables (e.g., EBAY_APP_ID, EBAY_CERT_ID)
// You can obtain these from your eBay Developer Program account: https://developer.ebay.com/signin?tab=register
const EBAY_APP_ID = process.env.EBAY_APP_ID ?? '-- also called Client ID --';
const EBAY_CERT_ID = process.env.EBAY_CERT_ID ?? '-- also called Client Secret --';
const EBAY_RUN_IN_SANDBOX = process.env.EBAY_RUN_IN_SANDBOX === 'true'; // Set to 'true' in .env for sandbox
if (EBAY_APP_ID === '-- also called Client ID --' || EBAY_CERT_ID === '-- also called Client Secret --') {
console.error('Error: Please configure your eBay API credentials. Check your .env file or direct configuration.');
process.exit(1);
}
const eBay = new eBayApi({
appId: EBAY_APP_ID,
certId: EBAY_CERT_ID,
sandbox: EBAY_RUN_IN_SANDBOX, // Set to true for sandbox environment; false for production
// siteId: 0 // Example: Specify site ID for certain traditional APIs (e.g., 0 for US)
});
async function getExampleItem() {
try {
// Example: Fetch details for a specific item using the Buy Browse API
const itemId = 'v1|254188828753|0'; // A publicly accessible sample item ID
console.log(`Fetching item details for ID: ${itemId}...`);
const item = await eBay.buy.browse.getItem(itemId);
console.log('Successfully fetched item details:');
console.log(JSON.stringify(item, null, 2));
// Uncomment for a search example:
// console.log('\nPerforming a search for "laptop"...');
// const searchResults = await eBay.buy.browse.search({ q: 'laptop', limit: 3 });
// console.log('Search Results:');
// console.log(JSON.stringify(searchResults.itemSummaries, null, 2));
} catch (error: any) {
console.error('An error occurred during the API call:', error.message || error);
if (error.response) {
console.error('Detailed API Error Response:', error.response.data);
}
}
}
getExampleItem();
Errors
Common errors & fixes
"Unauthorized" or "Authentication required"
Missing or invalid API credentials (`appId`, `certId`) or an expired/incorrect access token.
fixEnsure `appId` and `certId` are correctly configured in `eBayApi` constructor or environment variables. Verify your access token is valid and refreshed if using OAuth2/Auth'N'Auth.
"Invalid API call, API error, or missing required parameter"
An incorrect endpoint, missing required parameters for an API call, or a malformed request body.
fixConsult the eBay API documentation and the `ebay-api` library examples for the specific API call. Double-check required parameters and their format.
"This API is not supported in the sandbox environment" or "The resource you requested cannot be found."
Attempting to call an eBay API that is only available in the production environment while `sandbox` is set to `true`, or the API version is not supported in the current environment.
fixChange `sandbox: false` in your `eBayApi` configuration and use production credentials if the API is production-only. Alternatively, check if a sandbox equivalent exists for your desired API or if you are using an outdated API version.
Audit
Dependencies
No dependency data recorded yet.