Build a sneaker price alert with a cron job

This example checks a list of style codes and sizes every hour. When the lowest ask for a size is at or below your target, it posts a message to a webhook. It uses plain Node.js and the Barcodes.gg resale price API.

Last checked:

Before you start

  • Node.js 18 or later. The script uses the built-in fetch and needs no packages.
  • A Barcodes.gg API token with the prices ability, on a Standard or higher plan.
  • A webhook URL that accepts a JSON body with a content field. A Discord channel webhook works.

The script

Send one test request for each style code first. Copy the exact site name and eu size label from that answer into the list:

// check-prices.mjs
const WATCH = [
  // maxPrice is in the currency of the matching site row
  { styleCode: "DZ5485-612", site: "StockX", eu: "42", maxPrice: 150 },
];

for (const item of WATCH) {
  const res = await fetch(`https://barcodes.gg/api/v2/prices/${encodeURIComponent(item.styleCode)}`, {
    headers: { Authorization: `Bearer ${process.env.BARCODES_TOKEN}` },
  });
  const body = await res.json();
  if (!res.ok || body.error) continue;

  for (const site of body.results.sites.filter((row) => row.site === item.site)) {
    const size = site.sizes.find((row) => row.eu === item.eu);
    if (size?.price == null || size.price > item.maxPrice) continue;
    await fetch(process.env.WEBHOOK_URL, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        content: `${item.styleCode} EU ${item.eu} on ${site.site} ${site.market ?? ""}: ${size.price} ${site.currency}`,
      }),
    });
  }
}

One marketplace can have more than one row, for example one per StockX market. The script checks each row of the site, so you can get one message per market.

Run it every hour

Add one line to the crontab of the server with crontab -e:

0 * * * * cd /opt/price-alert && BARCODES_TOKEN=your-token WEBHOOK_URL=your-webhook node check-prices.mjs

The job starts at the top of each hour. It sends one request per style code in the list.

Calls and cost

One style code checked every hour uses about 720 calls in a 30-day month. The Standard plan has 10,000 calls, so it covers about 13 style codes at this rate. A style code without cached prices is not charged.

  • Group sizes by style code. One request returns every size, so do not send one request per size.
  • Check slow-moving products less often, for example every six hours.
  • Read size.as_of before you act on an alert. is_stale is true when the newest price in the answer is older than 24 hours.

All fields are on the sneaker resale price API page. For alerts in a chat command, see the Discord price bot.

Get resale prices by API

Resale prices are on Standard (€49 per month) and higher plans. One answered request uses one call. A product without cached prices is not charged.

Guides

StockX, GOAT and Alias are trademarks of their owners. Barcodes.gg is not affiliated with them.