Two short scripts for Node 18 or newer, with nothing to install: a first call with fetch, and an async generator that pages through sales and prints a median.
Short answer: with Node 18 or newer, put your key in the COMPSAPI_KEY environment variable and fetch https://api.compsapi.com/v1/sold with an Authorization: Bearer header. Each request returns up to 240 completed eBay sales as JSON. A free key is 100 requests a month with no card.
Save as sold.mjs and run node sold.mjs.
const API = "https://api.compsapi.com/v1/sold";
const headers = { Authorization: `Bearer ${process.env.COMPSAPI_KEY}` };
const url = new URL(API);
url.search = new URLSearchParams({ q: "lego 75192", days: "90", size: "240" });
const res = await fetch(url, { headers });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(data.count, "sales, more pages:", data.next_page);
for (const item of data.items.slice(0, 5)) {
console.log(item.last_sold.slice(0, 10), item.price, item.format, item.title.slice(0, 50));
}
Output on 27 November 2026:
234 sales, more pages: true
2026-11-27 821.12 FIXED_PRICE Lego 75192 Star Wars UCS Millennium Falcon | NEW S
2026-11-27 698.33 FIXED_PRICE LEGO Star Wars UCS Millennium Falcon 75192 BRAND N
2026-11-27 229.99 FIXED_PRICE 75192 UCS Millennium Falcon READ DESCRIPTION Star
2026-11-27 767.08 FIXED_PRICE LEGO Star Wars 75192 UCS Millenium Falcon NEU & OV
2026-11-27 42.68 FIXED_PRICE Lego UCS Millennium Falcon 75192 - Horizontal Wall
This one asks for new sets above $300 over the last year, reads up to three pages and prints the median.
const API = "https://api.compsapi.com/v1/sold";
const headers = { Authorization: `Bearer ${process.env.COMPSAPI_KEY}` };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
async function* sold(q, params = {}, maxPages = 3) {
for (let page = 1; page <= maxPages; page++) {
const url = new URL(API);
url.search = new URLSearchParams({ q, size: "240", page: String(page), ...params });
let res = await fetch(url, { headers });
if (res.status === 429) {
await sleep(Number(res.headers.get("retry-after") ?? 5) * 1000);
res = await fetch(url, { headers });
}
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
yield* data.items;
if (!data.next_page) return;
await sleep(1000);
}
}
const prices = [];
for await (const item of sold("lego 75192", { condition: "new", days: "365", min_price: "300" })) {
prices.push(item.price);
}
prices.sort((a, b) => a - b);
const mid = Math.floor(prices.length / 2);
const median = prices.length % 2 ? prices[mid] : (prices[mid - 1] + prices[mid]) / 2;
console.log(prices.length, "sales, median", median.toFixed(2));
Output on 27 November 2026: 400 sales, median 749.79.
| Parameter | What it does |
|---|---|
q | Search words. Every word must be in the title. -case leaves a word out |
days, or start and end | How far back, 1 to 1095, or a fixed window written YYYY-MM-DD |
size, page | Up to 240 sales a page, then the next page while next_page is true |
condition | new, open_box, refurbished, used or parts |
min_price, max_price | Price range in USD |
site | One eBay site: US, UK, DE, FR, IT, ES, CA or AU |
best_offer=1 | Flags sales that closed on an accepted offer |
match=strict, exclude=junk | Leave out the wrong model, lots and accessories |
| Status | Meaning | What to do |
|---|---|---|
| 400 | A missing or invalid parameter, or a search too broad to run | Fix the request or narrow the words |
| 401 | Missing or invalid key | Check the header |
| 403 | Key expired, or the request had no User-Agent | Send a User-Agent header |
| 429 | Monthly quota used, or too many requests in a minute | On a rate limit, wait the seconds in Retry-After |
| 503 | A temporary problem on our side | Retry after a second or two |
Every error body is JSON with "ok": false and a message. Failed searches do not count towards your quota.
Call the API from your server and keep the key in an environment variable. In a Next.js or Express app that means a route of your own that calls CompsAPI and passes the rows on.
/v1/comps returns the median and the spread in one request. The Python guide covers the same ground with requests and pandas.
How do I get eBay sold listings in JavaScript? Call CompsAPI /v1/sold with fetch: one GET with your key in the Authorization header and the search in q. Node 18 or newer has fetch built in, so there is no package to install.
Can I call the API from the browser? Call it from your server. A key shipped in browser or mobile code can be copied by anyone who opens the page.
How do I page through results in Node? Send page=2, page=3 and so on while next_page is true. The async generator on this page does that and yields one sale at a time.
Does it work with TypeScript, Deno or Bun? The examples use only fetch, URL and URLSearchParams, which are web standards. They were run on Node 22.
100 free requests a month · every filter on · no card
eBay plus 12 more marketplaces on the same key
Get a free key