> ## Documentation Index
> Fetch the complete documentation index at: https://docs.azvian.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API reference

> Report a sale or lead, and reverse a refunded sale, from your own website or checkout

The API lets your own server tell Affiliate Manager about a sale, a lead or a refund. It is JSON over HTTPS, authenticated with a bearer token.

> [!WARNING]
>
> Call the API from your **server**, never from a visitor's browser. The token is a secret: anyone who has it can record referrals.

## Authentication

Find your token under **Integrations → API token**. Send it on every request:

```
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
```

Until a token exists the API is off and every call returns `401`. Requests are limited to **120 per minute**.

Base address: `https://YOUR-INSTALL/api/v1`

## Record a sale or a lead

`POST /referrals`

Credits a sale or a lead to an affiliate. Identify the affiliate by their **code** (`ref`) or by a **coupon** code.

| Field | Type | Notes |
| - | - | - |
| `ref` | string | The affiliate's code (the `ref` value from their link). Required unless `coupon` is given. |
| `coupon` | string | A coupon code that belongs to an affiliate. Required unless `ref` is given. |
| `program` | string | The program's address (slug). Recommended when you run more than one program. |
| `type` | `sale` or `lead` | Defaults to `sale`. |
| `external_id` | string | Your own id for this order or form (up to 191 characters). **Sending the same value again credits only once.** |
| `email` | string | The customer's email. Used for fraud checks. |
| `amount` | number | The sale value in the program's currency, for example `49.00`. |
| `amount_cents` | integer | The same in whole cents. Use one of `amount` and `amount_cents`. |
| `currency` | string | Three letters. |
| `notes` | string | Up to 1,000 characters. |

### Example

```bash theme={null}
curl -X POST https://YOUR-INSTALL/api/v1/referrals \
  -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" \
  -d '{"program":"your-program","type":"sale","external_id":"order-8841","coupon":"MAYA20","email":"buyer@example.com","amount":49.00}'
```

### Response

`201 Created` for a new referral, `200 OK` when the `external_id` was already recorded:

```json theme={null}
{
  "id": 42,
  "created": true,
  "type": "sale",
  "status": "approved",
  "commission": {
    "amount_cents": 980,
    "currency": "USD",
    "status": "pending",
    "payable_at": "2026-11-14"
  }
}
```

`commission` is `null` when nothing is earned (for example a lead that has not been marked won yet, or a purchase by the affiliate themselves).

### Errors

| Status | Meaning |
| - | - |
| `401` | The token is missing or wrong. |
| `404` | No affiliate or coupon matches. |
| `422` | The referral was refused (the affiliate is not approved, the program is not active, or the type is wrong), or a field failed validation. The `error` field says why. |

## Refund a sale

`POST /referrals/refund`

Tell Affiliate Manager that a sale was refunded. A commission that has not been paid yet is reversed.

| Field | Type | Notes |
| - | - | - |
| `external_id` | string | The id you sent when you recorded the sale. Required. |
| `program` | string | Narrows the match when the same id could exist in two programs. |

```bash theme={null}
curl -X POST https://YOUR-INSTALL/api/v1/referrals/refund \
  -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" \
  -d '{"external_id":"order-8841"}'
```

It returns the same shape as above with the new `status`, or `404` if no referral has that `external_id`.

## Credit visitors from your website

To carry an affiliate's `?ref=` code from the link to your contact form, add `https://YOUR-INSTALL/track.js` to your pages. It stores the code in a cookie and fills any form field named `affiliate_ref`. Send that value as `ref` when you report the lead. See [Connecting sales and leads](https://docs.azvian.com/affiliate-manager/connecting-sales.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.