API Documentation

Getting Started

Performance & Caching

Most endpoints read cached figures and are cheap enough to poll. A few recalculate from the order history and are deliberately expensive; those are cached and throttled so one client cannot make the database do unbounded work.

What is cached

EndpointBehaviour
/coupons/{id}/stats (all-time)Reads the stored snapshot — the same figures the affiliate dashboard shows. One meta read. Reports source: "cache".
/coupons/{id}/stats (with from/to, or refresh=true)Recalculates from the orders. Each range is cached 60 seconds; an uncached calculation is limited to one per coupon per minute.
/coupons/{id}/ordersThe prepared list is cached whole for 60 seconds per coupon + range + status, so paginating through it costs nothing. An uncached combination is limited to one per coupon per minute.
/affiliates/{id}/stats (with dates)Cached 60 seconds per range; uncached calculations limited to one per affiliate per minute.
/reports/summaryCached 5 minutes per top value. refresh=true bypasses it.
Everything elseAnswered live from indexed queries.

Throttle responses

When an uncached recalculation is asked for inside the one-per-minute window, the response is 429 with code wcusage_api_throttled and retry_after: 60. The one exception is all-time coupon stats, which return the stored snapshot with source: "throttled" rather than failing.

Tip
Poll a fixed date range rather than a moving one. A client that keeps asking for yesterday is always served from cache; a client that shifts the range slightly on every call forces a fresh scan each minute and will start seeing 429s.

Working efficiently

  • For "what changed?", poll /events?after={id} — one cheap indexed query — or use webhooks and stop polling altogether.
  • For "how is the program doing?", one call to /reports/summary replaces walking every affiliate.
  • Use per_page=100 on collections instead of many small pages.
  • Prefer all-time stats (no from/to) for frequent reads; ask for a range only when you need one.