API Documentation

Intégrations

Recipes

Sync new referrals into another system

Poll the change feed and keep a cursor — one indexed query per poll, no matter how busy the program is:

curl -s "https://example.com/wp-json/wcusage/v2/events?after=9912&event=referral&per_page=100" \
  -H "Authorization: Bearer $WCUSAGE_KEY" -D headers.txt

# the new cursor for next time
grep -i '^X-WCUsage-Last-Event' headers.txt

On PRO, subscribe a webhook to referral.created and skip the polling entirely.

Build a monthly affiliate statement

# totals for the month
GET /wp-json/wcusage/v2/affiliates/1456/stats?from=2026-07-01&to=2026-07-31

# the orders behind them, one coupon at a time
GET /wp-json/wcusage/v2/coupons/8338/orders?from=2026-07-01&to=2026-07-31&per_page=100

Keep the range fixed between calls so both are served from cache rather than rescanned.

Auto-approve applications that meet your criteria

# 1. find pending applications
GET /wp-json/wcusage/v2/registrations?status=pending&per_page=100

# 2. approve the ones that qualify
POST /wp-json/wcusage/v2/registrations/512/status
{ "status": "accepted", "message": "Welcome aboard!", "send_email": true }

Needs an admin key with write. Remember that accepting is one-way through the API, so apply your criteria before calling, not after.

Give an affiliate read-only API access to their own data

POST /wp-json/wcusage/v2/keys
{ "user_id": 1456, "description": "Sarah's reporting script", "scopes": ["read"], "expires": "2027-01-01" }

The resulting key can call /me, /affiliates/1456/stats, its own coupons, their orders and click stats, and /payouts filtered to itself — and nothing else. Creating it requires manage plus the capability to edit that user.

Reconcile payouts with your accounting system

# everything paid in a period
GET /wp-json/wcusage/v2/payouts?status=paid&from=2026-07-01&to=2026-07-31&per_page=100

Match on transaction_id where your gateway provides one, and on id otherwise. date is when the payout was requested and date_paid when it was settled — use the latter for period allocation.

Flag a payout-fraud pattern

Subscribe a webhook to affiliate.payout_details_updated et payout.requested. When both arrive for the same user_id within a short window, hold the payout for manual review:

POST /wp-json/wcusage/v2/payouts/321/status
{ "status": "cancel" }

Cancelling returns the amount to the affiliate's unpaid balance, so nothing is lost; re-open it with pending once you are satisfied.

Refresh stale coupon statistics nightly

GET /wp-json/wcusage/v2/coupons/8338/stats?refresh=true

Rebuilds the stored snapshot from the order history and saves it, so the affiliate's dashboard and every later API read are current. Needs the write scope, and is limited to one rebuild per coupon per minute — space the calls out, and treat source: "throttled" as "try this one again later".

Check the health of your integration

GET /wp-json/wcusage/v2/me            # what am I, and what may I do?
GET /wp-json/wcusage/v2/webhooks      # failures, last_error, last_delivery
GET /wp-json/wcusage/v2/keys          # last_used, status, date_expires

A webhook with a rising failures count, or a key whose last_used has gone stale, is usually the first sign that something upstream broke.