`lumail@2.1.0` · [`lumail.campaigns`](/docs/sdk/v2/campaigns)

```typescript
campaigns.create(params: CreateCampaignParams): Promise<LumailResult<CreateCampaignResponse>>
```

Creates a draft.

## Body Parameters

| Name | Type | Description |
| ------------- | ------------------------------------ | ---------------------------------------------------- |
| `subject` | string | **Required.** Subject line. |
| `name` | string | Internal name. Defaults from `subject` when omitted. |
| `preview` | string or null | Preview / preheader text. |
| `content` | unknown | Campaign body (TipTap / markdown document). |
| `contentType` | `"MAILY"` / `"PLATE"` / `"MARKDOWN"` | Editor format. |
| `senderId` | string | Sending identity id. |
| `replyTo` | string or null | Reply-To address. |

## Response Fields

| Field | Type | Description |
| ------------- | ---------------- | ---------------------------- |
| `id` | string | Campaign id. |
| `name` | string | Internal name. |
| `subject` | string | Subject line. |
| `preview` | string or null | Preview text. |
| `status` | `CampaignStatus` | Usually `DRAFT`. |
| `contentType` | `ContentType` | Editor format. |
| `senderId` | string | Sending identity id. |
| `replyTo` | string or null | Reply-To address. |
| `createdAt` | string | Optional ISO 8601 timestamp. |

`data` is the campaign write result. Failures return `{ data: null, error: { name, message, statusCode } }`.


## API Reference
**Method:** POST
**Endpoint:** /api/v2/campaigns

### SDK
```ts
import { Lumail } from "lumail";

const lumail = new Lumail({ apiKey: process.env.LUMAIL_API_KEY });
const { data, error } = await lumail.campaigns.create({
  name: "Launch",
  subject: "Hello",
});
if (error) {
  throw error;
}
console.log(data.id, data.status);
```

### cURL
```bash
curl -X POST https://lumail.io/api/v2/campaigns \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Launch","subject":"Hello"}'
```

### JavaScript
```javascript
const response = await fetch("https://lumail.io/api/v2/campaigns", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ name: "Launch", subject: "Hello" }),
});
const data = await response.json();
```

### Success Response
```json
{
  "id": "cmp_abc123",
  "name": "Launch",
  "subject": "Hello",
  "preview": null,
  "status": "DRAFT",
  "contentType": "MAILY",
  "senderId": "snd_abc123",
  "replyTo": null
}
```

### Error Response
```json
{
  "name": "validation_error",
  "message": "subject is required",
  "statusCode": 422
}
```
