> ## 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.

# Connecting sales and leads

> Credit Gumroad sales by coupon code, report leads from your website, or credit a referral by hand

Everything on this page is under **Integrations** in the app, with your own address and token already filled in. Choose the route that matches how you sell.

> [card] [Selling on Gumroad](#selling-on-gumroad-or-any-shop-with-discount-codes)
>
> Sales are credited by discount code.

> [card] [A website with a contact form](#a-website-with-a-contact-form-leads)
>
> Credit leads with a script and a JSON call.

> [card] [Anything else](#anything-else)
>
> Credit a sale or deal by hand.

## Selling on Gumroad (or any shop with discount codes)

A visitor's browser cannot carry a cookie into Gumroad's checkout, so sales there are credited by **discount code**.

**1. Add a coupon for the affiliate**

On the affiliate's page, add a coupon code, for example `MAYA20`.

**2. Create the same code on Gumroad**

On Gumroad's Discounts page, create the same code with the discount buyers should get.

**3. Copy your ping address**

Under **Integrations → Credit Gumroad sales**, choose the program and copy the address it shows.

**4. Paste it into Gumroad**

In Gumroad, open **Settings → Advanced** and paste the address as the **Ping** address.

When a buyer uses `MAYA20`, Maya is credited automatically. A refund reverses the commission if it has not been paid yet.

> [!WARNING]
>
> Gumroad allows **one ping address per account**. If another system already uses it, that system has to pass each ping on to this address.

A sale without the code cannot be credited, because the checkout carries no cookie. Give each affiliate their code to share together with their link.

## A website with a contact form (leads)

Use this for services and anything you close by hand: the visitor fills in a form, and you decide later whether it became a client.

**1. Add the script to every page**

```html theme={null}
<script src="https://YOUR-INSTALL/track.js" defer></script>
```

It remembers the `?ref=` code in a cookie, and fills any form field named `affiliate_ref` for you.

**2. Report the lead from your server**

When the form is sent, your website's **server** reports the lead. Never do this from the visitor's browser: the token is a secret.

```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":"lead","external_id":"form-1042","ref":"AFFILIATE_CODE","email":"client@example.com"}'
```

**3. Mark it won**

When you win the client, open **Referrals**, enter the deal value next to the lead and press **Won**. The commission is earned then, and held for the hold period.

Sending the same `external_id` twice credits only once, so retries are safe. To report a finished **sale** instead, use `"type":"sale"` and an `"amount"`. Every field is described in the [API reference](https://docs.azvian.com/affiliate-manager/api.md).

## Anything else

Credit a sale or deal yourself under **Referrals → Credit a referral by hand**: choose the affiliate, **Sale** or **Lead**, enter the amount and press **Credit referral**.

## The API token

**Integrations → API token** shows the bearer token your website uses. You can replace it at any time; whatever used the old one must be updated, because it stops working immediately. Treat it like a password.

## How a referral is recorded

Every route above ends in the same place, which applies the same rules:

* Only an **approved affiliate in an active program** earns. Anyone else's referral is refused.
* A referral is recorded **once**: the same `external_id` is never credited twice.
* A purchase made **by the affiliate themselves** is recorded but earns nothing.
* A sale earns its commission straight away and holds it for the hold period. A lead earns only when you mark it won.
* A refund reverses a commission that has not been paid. A refund after payment is marked with a note, and recovering that money is up to you.
* Suspicious referrals are flagged for review. See [Reports and fraud checks](https://docs.azvian.com/affiliate-manager/reports-and-review.md#needs-review).


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