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

Update an existing campaign's metadata and content. Only campaigns with DRAFT status can be updated. For scheduled campaigns, cancel the schedule first.

## Response

- **Success (200 OK)** - Returns the updated campaign object.
- **Error (400 Bad Request)** - Campaign is not in DRAFT status or invalid sender ID.
- **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 Schema

| Field         | Type   | Description                                   |
| ------------- | ------ | --------------------------------------------- |
| `name`        | string | Internal name for the campaign                |
| `subject`     | string | Email subject line                            |
| `preview`     | string | Preview text shown in email clients           |
| `content`     | object | Email content in TipTap JSON format           |
| `contentType` | string | Content type: `MAILY`, `PLATE`, or `MARKDOWN` |
| `senderId`    | string | Email sender ID                               |
| `replyTo`     | string | Reply-to email address                        |

All fields are optional. Only provided fields will be updated.

## Response Fields

| Field                     | Type           | Description                                      |
| ------------------------- | -------------- | ------------------------------------------------ |
| `success`                 | boolean        | Indicates if the operation was successful        |
| `campaign`                | object         | The updated campaign object                      |
| `campaign.id`             | string         | Unique identifier for the campaign               |
| `campaign.campaignId`     | string         | Same as id (for consistency)                     |
| `campaign.name`           | string         | Name of the campaign                             |
| `campaign.subject`        | string         | Email subject line                               |
| `campaign.preview`        | string or null | Preview text for the email                       |
| `campaign.status`         | string         | Campaign status (DRAFT)                          |
| `campaign.contentType`    | string         | Content type: MAILY, PLATE, or MARKDOWN          |
| `campaign.content`        | object         | Email content in TipTap JSON format              |
| `campaign.replyTo`        | string or null | Reply-to email address                           |
| `campaign.senderId`       | string         | Email sender ID                                  |
| `campaign.recipientCount` | number         | Number of recipients                             |
| `campaign.createdAt`      | string         | ISO timestamp when the campaign was created      |
| `campaign.updatedAt`      | string         | ISO timestamp when the campaign was last updated |
| `campaignId`              | string         | Campaign ID at the root level for convenience    |

## Important Notes

- **Only DRAFT campaigns can be updated.** Scheduled, sending, or sent campaigns cannot be modified.
- To update a scheduled campaign, you must first cancel the schedule using the Lumail UI.
- When updating the `senderId`, the sender must exist and belong to your organization.

## Usage Example

Use this API endpoint to:

- Update campaign subject lines and preview text
- Modify email content programmatically
- Change the sender for a campaign
- Build campaign editing interfaces
- Sync campaign updates from external systems

## 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
- [Delete Campaign](/docs/api-reference/api-campaign-delete) - Delete a campaign


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

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

await lumail.campaigns.update("cmp_abc123xyz", {
  subject: "Updated Subject Line",
  preview: "New preview text",
});
```

### cURL
```bash
curl -X PATCH https://lumail.io/api/v1/campaigns/cmp_abc123xyz \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"subject": "Updated Subject Line", "preview": "New preview text"}'
```

### JavaScript
```javascript
const campaignId = 'cmp_abc123xyz';
const response = await fetch(`https://lumail.io/api/v1/campaigns/${campaignId}`, {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    subject: 'Updated Subject Line',
    preview: 'New preview text'
  }),
});

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}"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}
payload = {
    "subject": "Updated Subject Line",
    "preview": "New preview text"
}

response = requests.patch(url, json=payload, headers=headers)
data = response.json()
print(data)
```

### Success Response
```json
{
  "success": true,
  "campaign": {
    "id": "cmp_abc123xyz",
    "campaignId": "cmp_abc123xyz",
    "name": "Welcome Newsletter",
    "subject": "Updated Subject Line",
    "preview": "New preview text",
    "status": "DRAFT",
    "contentType": "MAILY",
    "content": {
      "type": "doc",
      "content": [...]
    },
    "replyTo": null,
    "senderId": "snd_xyz789abc",
    "recipientCount": 0,
    "createdAt": "2025-01-15T10:30:00.000Z",
    "updatedAt": "2025-01-15T16:45:00.000Z"
  },
  "campaignId": "cmp_abc123xyz"
}
```

### Error Response
```json
{
  "message": "Only DRAFT campaigns can be updated. Cancel the schedule first if the campaign is scheduled."
}
```
