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

# Affiliates

Manage affiliates within your campaigns.

## Endpoints

| Method | Endpoint                                              | Description                               |
| ------ | ----------------------------------------------------- | ----------------------------------------- |
| GET    | `/v1/campaigns/:campaign_id/affiliates`               | List affiliates                           |
| POST   | `/v1/campaigns/:campaign_id/affiliates`               | Invite an affiliate (returns invite link) |
| DELETE | `/v1/campaigns/:campaign_id/affiliates/:affiliate_id` | Remove an affiliate                       |

***

## List Affiliates

Get all affiliates for a specific campaign.

```bash theme={null}
GET /v1/campaigns/:campaign_id/affiliates
```

### Query Parameters

| Param  | Type   | Default | Description                             |
| ------ | ------ | ------- | --------------------------------------- |
| status | string | -       | Filter: `active`, `pending`, `rejected` |
| limit  | number | 50      | Results per page                        |
| offset | number | 0       | Pagination offset                       |

### Response

```json theme={null}
{
  "affiliates": [
    {
      "id": "aff_user123",
      "email": "john@example.com",
      "name": "John Doe",
      "status": "active",
      "unique_link": "https://c.baclique.com/summer-x7k2",
      "affiliate_code": "summer-x7k2",
      "joined_at": "2024-01-18T14:20:00Z",
      "stats": {
        "clicks": 1520,
        "conversions": 45,
        "revenue": 4500.00,
        "pending_commission": 450.00
      }
    }
  ],
  "pagination": {
    "limit": 50,
    "offset": 0,
    "total": 12
  }
}
```

***

## Invite Affiliate

Send an invitation to join your campaign. The affiliate must click the link to accept.

```bash theme={null}
POST /v1/campaigns/:campaign_id/affiliates
Content-Type: application/json
```

### Request Body

| Field | Type   | Required | Description               |
| ----- | ------ | -------- | ------------------------- |
| email | string | ✅        | Affiliate's email address |

### Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.baclique.com/v1/campaigns/cmp_abc123/affiliates \
    -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"email": "affiliate@example.com"}'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.baclique.com/v1/campaigns/cmp_abc123/affiliates', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer sk_live_YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      email: 'affiliate@example.com'
    })
  });

  const data = await response.json();
  ```
</CodeGroup>

### Response

```json theme={null}
{
  "status": "pending_invite",
  "email": "affiliate@example.com",
  "invite_link": "https://baclique.com/c/summer-sale?invite=abc123def456",
  "expires_at": "2025-01-08T14:00:00Z"
}
```

### Behavior

> ⚠️ **Important:** For privacy and consent reasons, affiliates are NOT added directly.

1. An **invitation link** is generated (valid for 7 days)
2. **You send this link** to the affiliate (via email, Slack, etc.)
3. The affiliate **clicks the link** and creates/logs into their BaClique account
4. They are then added to your campaign

This ensures the affiliate has given explicit consent to join your program.

***

## Remove Affiliate

Remove an affiliate from a campaign.

```bash theme={null}
DELETE /v1/campaigns/:campaign_id/affiliates/:affiliate_id
```

### Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE https://api.baclique.com/v1/campaigns/cmp_abc123/affiliates/aff_xyz789 \
    -H "Authorization: Bearer sk_live_YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.baclique.com/v1/campaigns/cmp_abc123/affiliates/aff_xyz789', {
    method: 'DELETE',
    headers: {
      'Authorization': 'Bearer sk_live_YOUR_API_KEY'
    }
  });

  const data = await response.json();
  ```
</CodeGroup>

### Response

```json theme={null}
{
  "success": true,
  "message": "Affiliate removed from campaign"
}
```

> ⚠️ **Note:** This removes the affiliate from the campaign but does not delete their historical data (clicks, conversions, commissions).

***

## Affiliate Statuses

| Status     | Description                                       |
| ---------- | ------------------------------------------------- |
| `active`   | Affiliate can generate links and earn commissions |
| `pending`  | Waiting for approval (private campaigns only)     |
| `rejected` | Application rejected by creator                   |

***

## Code Examples

### JavaScript - List All Affiliates

```javascript theme={null}
async function listAffiliates(campaignId) {
  const response = await fetch(
    `https://api.baclique.com/v1/campaigns/${campaignId}/affiliates`,
    {
      headers: {
        'Authorization': `Bearer ${process.env.BACLIQUE_API_KEY}`
      }
    }
  );
  
  return response.json();
}
```

### Python - Invite Affiliate

```python theme={null}
import requests
import os

def invite_affiliate(campaign_id, email):
    response = requests.post(
        f"https://api.baclique.com/v1/campaigns/{campaign_id}/affiliates",
        headers={
            "Authorization": f"Bearer {os.environ['BACLIQUE_API_KEY']}",
            "Content-Type": "application/json"
        },
        json={"email": email}
    )
    data = response.json()
    
    # Returns { status, email, invite_link, expires_at }
    print(f"Send this link to {email}: {data['invite_link']}")
    return data
```
