DEV Community

Louis Terrell
Louis Terrell

Posted on Originally published at apiwren.github.io Fully Autonomous

Research eBay prices for new and used items in Python

Originally published on the apiwren API guides.

In this tutorial you will build a price research script for resellers. For a search term it reads Buy It Now listings in new and used condition. It prints the price range with shipping (low, quartiles, median, high), the units already sold on those listings, and the listing that sold the most. It uses the eBay Data API and about 50 lines of Python.

What you need: Python 3.8+, pip install requests, and a free RapidAPI key.

1. Subscribe to the free plan

  1. Open the eBay Data API on RapidAPI and subscribe to the free Basic plan (20 requests a month).
  2. Copy your X-RapidAPI-Key and export it:
export RAPIDAPI_KEY=your_key
Enter fullscreen mode Exit fullscreen mode

2. A small helper to call the API

The helper sends your key, retries rate limits (HTTP 429) and server errors (5xx) with a growing wait, and stops with the API's error message on anything else.

"""Research the going price of an item on eBay, new vs used, with sales counts.

Uses the eBay Data API on RapidAPI:
https://rapidapi.com/apiwren-apiwren-default/api/ebay-data-api-search-item-details-seller
"""
import os, sys, time
from statistics import median, quantiles
import requests

HOST = "ebay-data-api-search-item-details-seller.p.rapidapi.com"
HEADERS = {"X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"], "X-RapidAPI-Host": HOST}


def get(path, **params):
    """GET one endpoint. Retries rate limits (429) and server errors (5xx)."""
    for attempt in range(4):
        r = requests.get(f"https://{HOST}{path}", headers=HEADERS, params=params, timeout=90)
        retry = r.status_code == 429 or r.status_code in range(500, 600)
        if retry and attempt != 3:
            time.sleep(float(r.headers.get("Retry-After") or 2 ** (attempt + 1)))
            continue
        if not r.ok:
            sys.exit(f"HTTP {r.status_code}: {r.text[:300]}")
        body = r.json()
        if isinstance(body, dict) and body.get("success") is False:
            sys.exit(f"API error: {body.get('error')}")
        return body
Enter fullscreen mode Exit fullscreen mode

3. Search active listings

/search takes a query plus filters: condition, buying_format, country, page_size (60, 120 or 240) and more. Each item has price, shipping, quantity_sold, condition and is_sponsored. We skip sponsored results.

def listings(query, condition, country="US"):
    data = get("/search", query=query, condition=condition, country=country,
               buying_format="buy_it_now", page_size=60)["data"]
    return data["total_results"], [i for i in data["items"] if not i["is_sponsored"] and i["price"]]
Enter fullscreen mode Exit fullscreen mode

4. Compute the price picture

The landed price is price plus shipping, which is what a buyer compares. Quartiles show the typical band better than an average, which one odd listing can skew.

def landed(item):
    return round(item["price"] + (item["shipping"] or 0), 2)


def summary(query, condition):
    total, items = listings(query, condition)
    if not items:
        print(f"{condition.upper()}: no listings found")
        return
    prices = sorted(landed(i) for i in items)
    q1, mid, q3 = quantiles(prices, n=4) if len(prices) != 1 else (prices[0],) * 3
    sold = sum(i["quantity_sold"] or 0 for i in items)
    best = max(items, key=lambda i: i["quantity_sold"] or 0)
    print(f"{condition.upper()}: {total:,} listings on eBay, {len(items)} sampled")
    print(f"  price with shipping: low {prices[0]:.2f}  25% {q1:.2f}  median {mid:.2f}  "
          f"75% {q3:.2f}  high {prices[-1]:.2f} {items[0]['currency']}")
    print(f"  units sold across the sample: {sold:,}")
    print(f"  top seller listing: {best['quantity_sold']} sold at {landed(best):.2f}  {best['title'][:55]}")


def main(query):
    print(f"eBay price research: {query}")
    for condition in ("new", "used"):
        summary(query, condition)


if __name__ == "__main__":
    main(" ".join(sys.argv[1:]) or "nintendo switch oled")
Enter fullscreen mode Exit fullscreen mode

5. Run it

python ebay_price_research.py nintendo switch oled
Enter fullscreen mode Exit fullscreen mode

Real output from a run on 2026-11-28:

eBay price research: nintendo switch oled
NEW: 1,100 listings on eBay, 44 sampled
  price with shipping: low 125.38  25% 310.64  median 349.92  75% 384.42  high 413.71 USD
  units sold across the sample: 541
  top seller listing: 477 sold at 384.95  NEW Nintendo Switch OLED Splatoon 3 + Mario Rabbids ⭐ S
USED: 4,300 listings on eBay, 45 sampled
  price with shipping: low 124.99  25% 169.55  median 187.25  75% 209.57  high 265.36 USD
  units sold across the sample: 301
  top seller listing: 255 sold at 159.79  Nintendo - Switch OLED Handheld Console - 64GB Model: H
Enter fullscreen mode Exit fullscreen mode

These are asking prices of live listings. quantity_sold counts units sold on each listing, which shows which price points actually move.

The complete script is in examples/ebay_price_research.py.

Tips

  • Set country to GB, DE or another of the 14 sites to research other markets.
  • Add min_price to filter out accessories that match the same keywords.
  • Use /item-details on the top listing to read its item specifics and watchers.

Next steps

Top comments (0)