eBay sold prices in Google Sheets
Pull eBay sold listings into Google Sheets with a short Apps Script function. Type =SOLDGRAPH_SOLD("item") in any cell.
Last updated
Add a custom function to your sheet, then type =SOLDGRAPH_SOLD("nintendo switch oled") in any cell. It fills in recent eBay sold listings: title, price, sold date and link. You need a Soldgraph API key and about two minutes.
#Set it up
- In your sheet, open Extensions → Apps Script.
- Open Project Settings → Script properties. Add a property named
SOLDGRAPH_KEYwith your API key as the value. Keep the key here, not in a cell, so people you share the sheet with can't see it. - Paste this into
Code.gsand save.
Code.gs
const API = "https://api.soldgraph.com"; /** * Recent eBay sold listings for a search. * @param {string} query What to search for, like "nintendo switch oled". * @customfunction */function SOLDGRAPH_SOLD(query) { const key = PropertiesService.getScriptProperties().getProperty("SOLDGRAPH_KEY"); if (!key) throw new Error("Add SOLDGRAPH_KEY in Project Settings → Script properties."); const headers = { Authorization: "Bearer " + key }; let body = get_(API + "/v1/ebay/sold?q=" + encodeURIComponent(query), headers); while (body.status === "pending") body = get_(API + body.poll_url + "?wait=20", headers); if (body.status === "failed") throw new Error("Search failed: " + body.error.code); const rows = body.result.data.map((r) => [r.title, r.displayed_price ? r.displayed_price.amount : "", r.sold_date || "", r.link]); return [["Title", "Price", "Sold", "Link"]].concat(rows);} function get_(url, headers) { const res = UrlFetchApp.fetch(url, { headers: headers, muteHttpExceptions: true }); const body = JSON.parse(res.getContentText()); if (res.getResponseCode() >= 400) throw new Error(body.error ? body.error.code : "HTTP " + res.getResponseCode()); return body;}- Back in the sheet, type
=SOLDGRAPH_SOLD("nintendo switch oled"). The rows spill down and across from that cell.
Add =MEDIAN(B2:B41) next to it for a middle price.
#Know before you use it
- Each recalculation is a search. Sheets reruns custom functions when you edit their input and sometimes when you reopen the sheet. Each run costs 1 request, even when it's served from our 15-minute cache.
- One page per call. You get one page of recent sales, not a full history.
- Custom functions time out after 30 seconds. Most searches finish in a few seconds. If one times out, recalculate the cell.
- Displayed prices aren't always final prices. See How prices work.
#Poshmark and Mercari
Change /v1/ebay/sold to /v1/poshmark/sold or /v1/mercari/sold. The rows have the same title, displayed_price, sold_date and link fields. Poshmark prices are asking prices, not what the buyer paid.