REST API - Affiliate Endpoints

AffiliateWP core 1.9+ offers two, read-only REST endpoints for affiliates:

  1. affiliates – Retrieves response objects for all affiliates on the current site
  2. affiliates/{ID} – Retrieves a response object for an affiliate with the given affiliate ID

The affiliate endpoints can be accessed via GET requests at the following locations:

http://example.com/wp-json/affwp/v1/affiliates
http://example.com/wp-json/affwp/v1/affiliates/ID

All affiliate endpoints and their various options are also discoverable by visiting the AffiliateWP REST namespace directly:

http://example.com/wp-json/affwp/v1/

Endpoints


The affiliates endpoint accepts any valid get_affiliates() arguments:

  • number – The number of results to retrieve (if available)
  • offset – The number of results to offset in the query. Default is 0 (no offset)
  • affiliate_id – The affiliate ID or array of IDs to query for.
  • user_id – The user ID or array of IDs to query payouts for.
  • exclude – Affiliate ID or array of IDs to exclude from the request.
  • search – Terms to search for affiliates. Accepts an affiliate ID or a string.
  • status – The affiliate status. Accepts 'active', 'inactive', 'pending', or 'rejected'.
  • order – How to order results. Accepts 'ASC' (ascending) or 'DESC' (descending).
  • orderby – Which field to order the response results by. Default is 'date'
  • fields – Specific fields to return for each affiliate in the response. Default '*' (all). Accepts 'ids' or any valid column

Additional arguments:

  • user – If user is passed as true, custom user objects will be retrieved on the fly for each affiliate in the response. Care should be taken when using this option due to the 1:1 increase in database queries associated with each affiliate
  • meta – If passed as true, an array of affiliate meta will be retrieved on the fly for each affiliate in the response. Just as with user, care should be taken due to the decreased performance impact.

All valid arguments can also be derived by sending an OPTIONS request to the either endpoint.

The affiliates/{ID} endpoint accepts any valid affiliate ID. Additionally, if user and/or meta are passed as true, a custom user object and/or array of affiliate meta will respectively be retrieved on the fly to include with the response.

Visibility

All endpoints require the API key and token except for the main affwp/v1 endpoint.

Response

Responses are returned in JSON form.

Example affiliates response:

[
  {
    "affiliate_id": 2736,
    "user_id": 1336,
    "rate": "",
    "rate_type": "",
    "payment_email": "",
    "status": "active",
    "earnings": 6,
    "unpaid_earnings": 0,
    "referrals": 6,
    "visits": 0,
    "date_registered": "2016-08-17 19:46:25",
    "id": 2736
  },
  {
    "affiliate_id": 2737,
    "user_id": 1337,
    "rate": "",
    "rate_type": "",
    "payment_email": "",
    "status": "inactive",
    "earnings": 1,
    "unpaid_earnings": 3145.59,
    "referrals": 1,
    "visits": 0,
    "date_registered": "2016-08-17 19:46:25",
    "id": 2737
  }
]<br>

Example affiliates/{ID} response:

{
  "affiliate_id": 2737,
  "user_id": 1337,
  "rate": "",
  "rate_type": "",
  "payment_email": "",
  "status": "inactive",
  "earnings": 1,
  "unpaid_earnings": 3145.59,
  "referrals": 1,
  "visits": 0,
  "date_registered": "2016-08-17 19:46:25"
}<br>

Example affiliates{ID}?user=1 response:

{
  "affiliate_id": 2737,
  "user_id": 1337,
  "rate": "",
  "rate_type": "",
  "payment_email": "",
  "status": "inactive",
  "earnings": 1,
  "unpaid_earnings": 3145.59,
  "referrals": 1,
  "visits": 0,
  "date_registered": "2016-08-17 19:46:25",
  "user": {
    "ID": "1337",
    "user_login": "user_1_11",
    "user_nicename": "user_1_11",
    "user_url": "",
    "user_registered": "2016-08-17 19:46:25",
    "user_status": "0",
    "display_name": "User 11",
    "spam": "0",
    "deleted": "0",
    "first_name": "",
    "last_name": ""
  }
}

Example affiliates{ID}?meta=1 response:

{
  "affiliate_id": 2737,
  "user_id": 1337,
  "rate": "",
  "rate_type": "",
  "payment_email": "pay@2737.dev",
  "status": "active",
  "earnings": 32039.07,
  "unpaid_earnings": 3145.59,
  "referrals": 3192,
  "visits": 0,
  "date_registered": "2016-08-17 19:46:25",
  "meta": {
    "some_key": [
      "some_value"
    ]
  },
  "id": 2737
}<br>

.