PY 02: Your first query

Track: Code (Python client + raw REST) Prerequisite: PY_01.

The task

Run a first client.query(...) call against one table, and see the same request expressed as a raw requests.post call to understand the underlying REST shape.

Starter steps

  1. Query recently sold watch lots using the client:
rows = client.query(
    "all_watches_data",
    fields=["designer", "model", "item_title", "sale_date", "usd_price_decimal", "vendor"],
    filters=[{"field": "status", "op": "eq", "value": "sold"}],
    sort=[{"field": "sale_date", "direction": "desc"}],
    limit=20,
)
print(len(rows))
print(rows[0])
  1. See the equivalent raw REST call, which is what client.query(...) sends on your behalf:
import requests

API_KEY = "YOUR_CLASS_KEY"
resp = requests.post(
    "https://api.altfndata.com/v1/tables/all_watches_data/query",
    headers={"X-API-Key": API_KEY, "Content-Type": "application/json"},
    json={
        "fields": ["designer", "model", "item_title", "sale_date", "usd_price_decimal", "vendor"],
        "filters": [{"field": "status", "op": "eq", "value": "sold"}],
        "sort": [{"field": "sale_date", "direction": "desc"}],
        "limit": 20,
    },
)
payload = resp.json()
print(payload["table"], payload["result_count"])
rows = payload["data"]
  1. Note that client.query(...) returns the data array directly, already parsed into Python dicts, while the raw call returns the full envelope (table, result_count, data) and you extract data yourself.
  2. Change limit=20 to limit=50 and re-run, confirming len(rows) and payload["result_count"] both track the requested limit, not a total row count for the whole table.

Expected result

rows is a Python list of dicts, one per lot, each with keys matching your fields list (designer, model, item_title, sale_date, usd_price_decimal, vendor). len(rows) equals 20 (or your limit), assuming that many sold lots exist. The raw REST call returns the same rows inside payload["data"], with payload["result_count"] equal to the number of rows on this page, not the total number of matching rows in the table.

Stretch challenge

Rewrite the query to pull the same fields from all_handbags_data instead, changing only the table name argument, and confirm the client call and the raw REST call both still work unchanged in every other respect.