`POST https://lumail.io/api/v1/campaigns/{campaignId}/send`

Send a campaign immediately or schedule it for later delivery. Only campaigns in DRAFT status can be sent.

## Response

- **Success (200 OK)** - Campaign has been scheduled for sending.
- **Error (400 Bad Request)** - Campaign is not in DRAFT status, missing unsubscribe link, or scheduledAt is in the past.
- **Error (404 Not Found)** - Campaign not found or doesn't belong to your organization.
- **Error (401 Unauthorized)** - Invalid or missing API token.

## Path Parameters

| Parameter    | Type   | Description                          |
| ------------ | ------ | ------------------------------------ |
| `campaignId` | string | **Required.** The unique campaign ID |

## Request Body

| Field         | Type   | Default | Description                                                             |
| ------------- | ------ | ------- | ----------------------------------------------------------------------- |
| `scheduledAt` | string | —       | ISO 8601 datetime for scheduled delivery. Omit to send immediately.     |
| `timezone`    | string | `"UTC"` | Timezone for scheduling (e.g., `"Europe/Paris"`, `"America/New_York"`). |

## Response Fields

| Field                  | Type    | Description                                |
| ---------------------- | ------- | ------------------------------------------ |
| `success`              | boolean | Indicates if the operation was successful  |
| `campaign.id`          | string  | The campaign ID                            |
| `campaign.status`      | string  | Updated status (always `"SCHEDULED"`)      |
| `campaign.scheduledAt` | string  | The scheduled send time in ISO 8601 format |
| `campaign.timezone`    | string  | The timezone used for scheduling           |
| `campaignId`           | string  | The campaign ID (convenience field)        |

## Important Notes

- **Only DRAFT campaigns can be sent.** Scheduled, sending, sent, or archived campaigns cannot be sent again.
- **Unsubscribe link required.** Your campaign content must include `{{unsubscribeUrl}}`. The API will return an error if it's missing.
- **Omit `scheduledAt` to send immediately.** The campaign will begin sending right away.
- **`scheduledAt` must be in the future.** Past dates will return a 400 error.
- Once sent, the campaign status transitions: `DRAFT` → `SCHEDULED` → `SENDING` → `SENT`.

## Usage Example

Use this API endpoint to:

- Trigger campaign sends from your own application or CRM
- Schedule campaigns for optimal delivery times
- Build automated campaign workflows with external tools
- Integrate campaign sending into CI/CD or marketing automation pipelines

## Related Documentation

- [List Campaigns](/docs/api-reference/api-campaigns-get) - List all campaigns
- [Create Campaign](/docs/api-reference/api-campaigns-post) - Create a new campaign
- [Get Campaign](/docs/api-reference/api-campaign-get) - Get details for a specific campaign
- [Update Campaign](/docs/api-reference/api-campaign-patch) - Update a campaign
- [Delete Campaign](/docs/api-reference/api-campaign-delete) - Delete a campaign


## API Reference
**Method:** POST
**Endpoint:** /api/v1/campaigns/{campaignId}/send

### SDK
```ts
import { Lumail } from "lumail";
const lumail = new Lumail({ apiKey: "YOUR_API_TOKEN" });

// Send immediately
await lumail.campaigns.send("cmp_abc123xyz");

// Schedule for later
await lumail.campaigns.send("cmp_abc123xyz", {
  scheduledAt: "2025-03-15T14:00:00.000Z",
  timezone: "Europe/Paris",
});
```

### cURL
```bash
# Send immediately
curl -X POST https://lumail.io/api/v1/campaigns/cmp_abc123xyz/send \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

# Schedule for later
curl -X POST https://lumail.io/api/v1/campaigns/cmp_abc123xyz/send \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "scheduledAt": "2025-03-15T14:00:00.000Z",
    "timezone": "Europe/Paris"
  }'
```

### JavaScript
```javascript
const campaignId = 'cmp_abc123xyz';

// Send immediately
const response = await fetch(`https://lumail.io/api/v1/campaigns/${campaignId}/send`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({}),
});

// Schedule for later
const response = await fetch(`https://lumail.io/api/v1/campaigns/${campaignId}/send`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    scheduledAt: '2025-03-15T14:00:00.000Z',
    timezone: 'Europe/Paris',
  }),
});

const data = await response.json();
console.log(data);
```

### Python
```python
import requests

campaign_id = "cmp_abc123xyz"
url = f"https://lumail.io/api/v1/campaigns/{campaign_id}/send"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}

# Send immediately
response = requests.post(url, headers=headers, json={})

# Schedule for later
response = requests.post(url, headers=headers, json={
    "scheduledAt": "2025-03-15T14:00:00.000Z",
    "timezone": "Europe/Paris"
})

data = response.json()
print(data)
```

### Success Response
```json
{
  "success": true,
  "campaign": {
    "id": "cmp_abc123xyz",
    "status": "SCHEDULED",
    "scheduledAt": "2025-03-15T14:00:00.000Z",
    "timezone": "Europe/Paris",
    "campaignId": "cmp_abc123xyz"
  },
  "campaignId": "cmp_abc123xyz"
}
```

### Error Response
```json
{
  "message": "Campaign must be in DRAFT status to send. Current status: SENT"
}
```
