contract 2026-10-05
Build

Recipes

Six end-to-end flows that cover most of what the API is for. Each is a complete sequence, not a fragment.

Set API=https://api.thecarapi.com and KEY=your_key first.

1. Build a filter sidebar in one request

Six dimensions, one round trip, one unit of quota:

bash
curl -sS -H "X-API-Key: $KEY" --compressed \
  "$API/api/v1/facets?fields=brands,years,fuels,gearboxes,countries,sites"

Then narrow it as the user picks. Facets cross-filter: pass the filters already chosen and every remaining dimension re-counts against them, while each dimension still ignores its own filter so the user can change their mind.

bash
# After "BMW, under EUR 15,000": what fuels and years are left?
curl -sS -H "X-API-Key: $KEY" \
  "$API/api/v1/facets?fields=fuels,years&brand=bmw&price_to=15000"

Models are per-brand and stay on their own route:

bash
curl -sS -H "X-API-Key: $KEY" "$API/api/v1/models?brand=bmw&ordering=-count&limit=25"

Cache the sidebar. Facets are served max-age=600 with an ETag; store it and send If-None-Match and the refresh costs an empty 304.

2. Search, page it, and keep the totals honest

bash
curl -sS -H "X-API-Key: $KEY" --compressed \
  "$API/api/v1/vehicles?brand=bmw&fuel=Diesel&year_from=2018&sort=price_low&limit=50&page=1"
  • Paging. Follow pagination.next_cursor until it is null, sending it back as cursor with the same filters. page+page_size or offset+limit still work when you need to jump to a page; mixing the two spellings is a 400.
  • Counting is the expensive half. If you are streaming rather than showing a page count, send include_total=false and skip it entirely. If you want only the number, send count_only=true and get no rows.
  • Persist site + id. id is a string — japan ids do not fit a JSON number.
bash
# "How many diesel BMWs are there?" — one cheap call, no rows.
curl -sS -H "X-API-Key: $KEY" \
  "$API/api/v1/vehicles?brand=bmw&fuel=Diesel&count_only=true" | jq .pagination.total

3. Open one car: detail, live bid, photos

One request gets specification, condition and gallery together:

bash
curl -sS -D headers.txt -H "X-API-Key: $KEY" --compressed \
  "$API/api/v1/vehicles/openlane/11409652" -o car.json

Then branch on three things, in this order:

text
live_price          present  -> that IS the current bid; render it
live_price_pending  present  -> read once more after poll_after_seconds, then stop
neither                      -> the cycle price is the price; do not retry

is_blind: true      -> there will never be a price. Show prices.estimated_value,
                       labelled as the auction house's estimate.
details_pending: t  -> vehicle_details is not there yet. Re-read on the short
                       max-age the response carries; render the rest meanwhile.
vault_gallery.pending > 0 -> more photos are coming. Poll on max-age=10.

Photo URLs are paths, so join them to the base:

bash
jq -r '.data.vehicle.vault_gallery.images[] | .served_url // .remote_url' car.json \
  | sed "s|^/|$API/|"

You do not need /api/v1/vehicles/{site}/{id}/images as well — vault_gallery is that same body embedded. Use the separate route only when you want the gallery alone.

4. Shop the discounts, then price the import

With the market_reference field grant, top offers carry the reference used for their scoring:

bash
curl -sS -H "X-API-Key: $KEY" \
  "$API/api/v1/top-offers?site=openlane&min_savings_pct=20&sort=savings&limit=10"

Take one and cost it landed. Read is_margin off the detail response, and send the source so the fee model matches the one that priced the listing:

bash
curl -sS -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"price":9000,"site":"openlane","origin":"DE","destination":"BG","is_margin":false}' \
  "$API/api/v1/calculator/calculate" | jq .data.breakdown.estimated_total

Compare that landed total with the retail market, not with the lot price:

bash
curl -sS -H "X-API-Key: $KEY" \
  "$API/api/v1/cars-bg-market?brand=BMW&model=320d&year=2019&flex=1" \
  | jq '{n: .data.snapshot.listing_count, median: .data.snapshot.median_price_eur}'

Check listing_count before you trust the median. Market snapshots come with developer-portal trial and paid keys; on a key issued by hand, ask for them.

5. Track one car over time

Price movements for a lot you are watching:

bash
curl -sS -H "X-API-Key: $KEY" \
  "$API/api/v1/vehicles/openlane/11409652/price-history" \
  | jq '.data.items[] | {observed_at, current: .prices.current.amount, changed_fields}'

And its life before this listing, by VIN — this is what shows a car that has been through auction more than once:

bash
curl -sS -H "X-API-Key: $KEY" \
  "$API/api/v1/vin/WBA8E9G50GNU12345/history" \
  | jq '.data.items[] | {site, last_seen_at, mileage, public: .prices.public.amount, archived}'

VIN history is sold as VIN bundles, charged per VIN found: a lookup with match_count: 0 is free. event_type on price history is initial, baseline or change — there is no price_change value.

6. Mirror the whole feed, cheaply

To keep a local copy in sync rather than to answer a query:

bash
# First load: walk the feed by cursor at the maximum page size.
curl -sS -H "X-API-Key: $KEY" --compressed \
  "$API/api/v1/vehicles?limit=100&include_total=false"
# …then repeat with &cursor=<pagination.next_cursor> until it is null.

# From then on: only what is new or changed since your last sync.
curl -sS -H "X-API-Key: $KEY" --compressed \
  "$API/api/v1/vehicles/changes?since=2026-10-05T09:00:00Z"
# Follow pagination.next_cursor, then store data.next_since for next time.
The changes feed is granted on request. Without it, re-walk the feed and send each page’s ETag back.

Four things make this an order of magnitude cheaper:

  1. 1--compressed — roughly an eighth of the bytes.
  2. 2include_total=false — the count is the expensive half of a search.
  3. 3Store each page's ETag and send If-None-Match on the re-walk; unchanged pages answer 304 with no body.
  4. 4Do not expand every card. Hydrate detail only for rows whose last_changed_at moved, or that you actually display.

Search results are always cycle-priced, never live-priced. That is what makes them fast enough to page — see what stays on cycle prices.