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

# Campaigns

Manage your affiliate campaigns programmatically.

## Endpoints

| Method | Endpoint            | Description        |
| ------ | ------------------- | ------------------ |
| GET    | `/v1/campaigns`     | List all campaigns |
| GET    | `/v1/campaigns/:id` | Get a campaign     |
| POST   | `/v1/campaigns`     | Create a campaign  |
| PATCH  | `/v1/campaigns/:id` | Update a campaign  |
| DELETE | `/v1/campaigns/:id` | Archive a campaign |

***

## List Campaigns

```bash theme={null}
GET /v1/campaigns
```

### Query Parameters

| Param  | Type   | Default | Description                                      |
| ------ | ------ | ------- | ------------------------------------------------ |
| status | string | -       | Filter by status: `active`, `paused`, `archived` |
| limit  | number | 50      | Results per page (max 100)                       |
| offset | number | 0       | Pagination offset                                |

### Response

```json theme={null}
{
  "campaigns": [
    {
      "id": "cmp_abc123",
      "name": "Summer Sale 2024",
      "status": "active",
      "type": "CPA",
      "commission_type": "percentage",
      "commission_value": 10,
      "target_url": "https://example.com/summer",
      "created_at": "2024-01-15T10:30:00.000Z"
    }
  ],
  "pagination": {
    "limit": 50,
    "offset": 0,
    "total": 3
  }
}
```

***

## Get Campaign

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

### Response

```json theme={null}
{
  "campaign": {
    "id": "cmp_abc123",
    "name": "Summer Sale 2024",
    "slug": "summer-sale-2024-x7k2",
    "target_url": "https://example.com/summer",
    "type": "CPA",
    "status": "active",
    "commission_type": "percentage",
    "commission_value": 10,
    "attribution_window": 30,
    "max_budget": 10000,
    "current_spend": 3180,
    "created_at": "2024-01-15T10:30:00.000Z",
    "stats": {
      "total_affiliates": 45,
      "total_clicks": 12500,
      "total_conversions": 320,
      "total_revenue": 31800.00
    }
  }
}
```

***

## Create Campaign

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

### Request Body

| Field               | Type   | Required | Description                                         |
| ------------------- | ------ | -------- | --------------------------------------------------- |
| name                | string | ✅        | Campaign name                                       |
| target\_url         | string | ✅        | Destination URL                                     |
| type                | string | ✅        | `CPA` (conversion-based)                            |
| commission\_type    | string | ✅        | `fixed` or `percentage`                             |
| commission\_value   | number | ✅        | Commission amount                                   |
| visibility          | string | -        | `public` (default) or `private`                     |
| attribution\_window | number | -        | Days to track conversions (default: 30)             |
| maturation\_days    | number | -        | Days before commission is withdrawable (default: 7) |

### Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.baclique.com/v1/campaigns \
    -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Black Friday 2024",
      "target_url": "https://example.com/blackfriday",
      "type": "CPA",
      "commission_type": "percentage",
      "commission_value": 15,
      "visibility": "public"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.baclique.com/v1/campaigns', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer sk_live_YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: 'Black Friday 2024',
      target_url: 'https://example.com/blackfriday',
      type: 'CPA',
      commission_type: 'percentage',
      commission_value: 15,
      visibility: 'public'
    })
  });

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

### Response

```json theme={null}
{
  "success": true,
  "campaign": {
    "id": "cmp_xyz789",
    "name": "Black Friday 2024",
    "slug": "black-friday-2024-abc123",
    "target_url": "https://example.com/blackfriday",
    "type": "CPA",
    "status": "active",
    "created_at": "2024-01-20T10:30:00.000Z"
  }
}
```

***

## Update Campaign

```bash theme={null}
PATCH /v1/campaigns/:id
Content-Type: application/json
```

### Request Body

All fields are optional. Only include what you want to update.

```json theme={null}
{
  "name": "Updated Campaign Name",
  "status": "paused",
  "commission_value": 20,
  "maturation_days": 14
}
```

### Example

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

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

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

### Response

```json theme={null}
{
  "success": true,
  "campaign": {
    "id": "cmp_abc123",
    "name": "Updated Campaign Name",
    "slug": "updated-campaign-name-x7k2",
    "target_url": "https://example.com/updated",
    "type": "CPA",
    "status": "paused",
    "commission_type": "percentage",
    "commission_value": 20,
    "created_at": "2024-01-15T10:30:00.000Z"
  }
}
```

***

## Archive Campaign

Archiving a campaign stops all tracking but preserves historical data.

```bash theme={null}
DELETE /v1/campaigns/:id
```

### Example

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

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

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

### Response

```json theme={null}
{
  "success": true,
  "message": "Campaign archived"
}
```

> 💡 **Tip:** Archived campaigns can be reactivated by updating their status to `active`.
