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

# Affiliate API

> Read your own affiliate account on a store with a key you create yourself

The Affiliate API is for **affiliates**, not store owners. If you promote a store through its affiliate programme, you can read your own account with it: your balance, the discount your code gives on each product, the orders you referred and the payouts the store has made to you.

It does not use merchant API keys, and merchant keys don't work on it.

```bash theme={null}
curl "https://api.komerza.com/affiliate/discounts" \
  -H "Authorization: Bearer kmrz_aff_YOUR_KEY" \
  -H "User-Agent: MyApp/1.0"
```

## Creating a key

1. Sign in to the store's customer dashboard with the email you're an affiliate under
2. Open **Affiliates**, then **API keys**
3. Click **Create key**, name it, and optionally restrict it to your server's IP addresses
4. Copy the key

> [!WARNING]
>
> The key is shown once and can't be retrieved later. Only a hash of it is
> stored. Keep it on your server: anyone holding it can read your affiliate
> account.

A key belongs to one affiliate account on one store. If you're an affiliate of several stores, create a key on each. You can hold up to 10 keys per store, and revoking one in the dashboard stops it working immediately.

## What a key can read

Every endpoint reads the account the key belongs to. None of them takes a store or affiliate ID, and no key can read another affiliate's data.

| Endpoint | Returns |
| - | - |
| [`GET /affiliate`](https://docs.komerza.com/api-reference/endpoint/affiliate/get-account) | Your code, referral link, discount and commission rates, and balance |
| [`GET /affiliate/discounts`](https://docs.komerza.com/api-reference/endpoint/affiliate/get-discounts) | The discount a buyer actually gets on each product with your code |
| [`GET /affiliate/orders`](https://docs.komerza.com/api-reference/endpoint/affiliate/get-orders) | The paid orders you referred, with the products bought |
| [`GET /affiliate/payouts`](https://docs.komerza.com/api-reference/endpoint/affiliate/get-payouts) | The payouts the store has recorded for you |
| [`GET /affiliate/stats`](https://docs.komerza.com/api-reference/endpoint/affiliate/stats) | Clicks, conversions and earnings over a recent window |

## Advertising your discount

Your account has a headline discount rate, but the store can give each product its own rate or turn the discount off for it. **Advertise what `GET /affiliate/discounts` returns, not the headline.** It is calculated exactly the way checkout calculates it, so it is what your buyers will see taken off.

The affiliate discount is applied after any coupon, to the amount the coupon leaves.

## When authentication fails

| Status | Meaning | Fix |
| - | - | - |
| `401` | Key missing, malformed or revoked | Check the `Bearer ` prefix is present, the key starts with `kmrz_aff_` and still exists |
| `403` | Called from an IP address the key isn't restricted to | Add the address to the key, or create a key without a restriction |
| `403` | The store has disabled your affiliate account | Contact the store. Keys stop working while the account is disabled |

Both return the standard error envelope, with `code` set to `AccessDenied`. See [Responses & Errors](https://docs.komerza.com/api-reference/responses.md).


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