API Documentation

Endpoints

API Key Management

Keys can be managed in the admin UI (Coupon Affiliates → Admin Tools → API) or programmatically. Every route here requires an admin with the manage scope.

List keys

GET /wp-json/wcusage/v2/keys

Standard pagination. Returns metadata only — never tokens or hashes:

[
  {
    "id": 4,
    "user_id": 1456,
    "description": "Zapier integration",
    "key_prefix": "wcus_9f2c1e",
    "scopes": ["read"],
    "status": "active",
    "last_used": "2026-08-07T13:55:00",
    "date_created": "2026-08-01T09:12:00",
    "date_expires": null
  }
]

key_prefix is the first 12 characters of the token — enough to recognise a key in your own logs, useless as a credential.

Create a key

POST /wp-json/wcusage/v2/keys

Body paramTypeDescription
user_idintegerThe user the key acts as. Defaults to the current user. Use an affiliate's user ID to create a key limited to their own data.
descriptionstringLabel, e.g. "Zapier integration". Up to 200 characters.
scopesarrayAny of read, write, manage. Default ["read"].
expiresdateOptional expiry (Y-m-d). The key stops working at the end of that day, in the site's timezone.
{
  "id": 4,
  "token": "wcus_9f2c1e4a7b3d5e6f8a9b0c1d2e3f4a5b6c7d8e9f",
  "notice": "Store this token now - it cannot be shown again.",
  "user_id": 1456
}
Warning
The token is returned only once, at creation, with 201. Only a SHA-256 hash is stored on the server, so a lost token cannot be recovered — revoke it and create another.

You may always create a key for yourself. Creating one for another user requires the capability to edit that user, so a lower-privileged manager cannot mint a key that acts as a full administrator. Otherwise the response is 403 wcusage_api_cannot_create_for_user.

Revoke a key

DELETE /wp-json/wcusage/v2/keys/{id}

{ "revoked": true }

Revocation is immediate: clients using the key receive 401 on their next request. It is idempotent — revoking an already-revoked key reports success. The same "could you edit that user" rule applies, so one plugin admin cannot destroy an administrator's integration credential.

Key creation and revocation are both recorded in the activity log (api_key_created, api_key_revoked), so they show up in /events.

Note
Permanent deletion of a key row is available on the admin screen only. The API offers revocation, which keeps the audit trail intact.