# Create campaign

URL: https://docs.hanzo.ai/docs/openapi/campaign/post-campaign

> Creates a campaign as a DRAFT and returns it.

`POST /v1/campaign`

> [Campaign →](https://docs.hanzo.ai/docs/openapi/campaign) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                        |
| ------------- | -------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/campaign`     |
| **Method**    | `POST`                                 |
| **Operation** | `post_campaign`                        |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY` |

Creates a campaign as a DRAFT and returns it.

A draft is inert: nothing is sent, no connector is touched and no budget is
committed until the campaign is launched. The channels named here are validated
and de-duplicated by kind (one executor per kind), and every channel starts
"pending" whatever the caller claims — a client can never assert a launched
state.

## Request

12 fields, body `application/json` (required).

| Field                   | In   | Type                    | Required | Description                                                                                                                                                                                     |
| ----------------------- | ---- | ----------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `audience`              | body | string                  | —        | Audience is the segment or audience selector this campaign targets.                                                                                                                             |
| `budget`                | body | integer (int64)         | —        | Budget is the campaign's total budget in CENTS.                                                                                                                                                 |
| `channels`              | body | campaign.ChannelSpec\[] | —        | Channels are the fan-out targets, at most one per kind (paid, organic, email) and at most 12.                                                                                                   |
| `channels[].account`    | body | string                  | —        | Account is the provider account this channel runs under: an ad-account, a page or a mailing-list id.                                                                                            |
| `channels[].detail`     | body | string                  | —        | Detail is the last outcome in one secret-free line — the failure reason, or what the executor reported.                                                                                         |
| `channels[].externalId` | body | string                  | —        | ExternalID is the provider-side id of the running execution, recorded by the orchestrator at launch and handed back verbatim to read spend or to pause.                                         |
| `channels[].kind`       | body | string                  | —        | Kind is the channel and the identity a campaign holds at most one of: paid, organic or email.                                                                                                   |
| `channels[].platform`   | body | string                  | —        | Platform is the provider within the kind — meta, google, x, instagram, or the email provider.                                                                                                   |
| `channels[].status`     | body | string                  | —        | Status is this channel's own launch outcome, not the campaign's: pending (added, never launched), live, paused, failed (Detail says why) or unavailable (no executor wired on this deployment). |
| `content`               | body | string\[]               | —        | Content is the ordered creative set.                                                                                                                                                            |
| `name`                  | body | string                  | —        | Name is the campaign's display name.                                                                                                                                                            |
| `scheduleAt`            | body | integer (int64)         | —        | ScheduleAt is when the campaign should run, in unix seconds.                                                                                                                                    |

## Response

| Status    | Body                    | Meaning |
| --------- | ----------------------- | ------- |
| `201`     | campaign.campaignRecord | created |
| `default` | problem-details         | refused |

`201` body — 16 fields.

| Field                   | In   | Type                    | Always | Description                                                                                                                                                                                     |
| ----------------------- | ---- | ----------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `audience`              | body | string                  | —      | Audience is an opaque reference to the segment this campaign targets.                                                                                                                           |
| `budget`                | body | integer (int64)         | —      | Budget is the campaign's total budget in CENTS, handed to each executor as the budget for its channel.                                                                                          |
| `channels`              | body | campaign.ChannelSpec\[] | —      | Channels are the fan-out targets, at most one per kind and at most 12, each carrying its own post-launch state.                                                                                 |
| `channels[].account`    | body | string                  | —      | Account is the provider account this channel runs under: an ad-account, a page or a mailing-list id.                                                                                            |
| `channels[].detail`     | body | string                  | —      | Detail is the last outcome in one secret-free line — the failure reason, or what the executor reported.                                                                                         |
| `channels[].externalId` | body | string                  | —      | ExternalID is the provider-side id of the running execution, recorded by the orchestrator at launch and handed back verbatim to read spend or to pause.                                         |
| `channels[].kind`       | body | string                  | —      | Kind is the channel and the identity a campaign holds at most one of: paid, organic or email.                                                                                                   |
| `channels[].platform`   | body | string                  | —      | Platform is the provider within the kind — meta, google, x, instagram, or the email provider.                                                                                                   |
| `channels[].status`     | body | string                  | —      | Status is this channel's own launch outcome, not the campaign's: pending (added, never launched), live, paused, failed (Detail says why) or unavailable (no executor wired on this deployment). |
| `content`               | body | string\[]               | —      | Content is the ordered creative set, at most 32, empty entries dropped.                                                                                                                         |
| `createdAt`             | body | integer (int64)         | —      | CreatedAt is when the campaign was created, in unix seconds.                                                                                                                                    |
| `id`                    | body | string                  | —      | ID is the campaign's server-minted handle — "cmp\_" and 128 random bits — and the id every other campaign call is addressed by.                                                                 |
| `name`                  | body | string                  | —      | Name is the campaign's display name.                                                                                                                                                            |
| `scheduleAt`            | body | integer (int64)         | —      | ScheduleAt is when the campaign should run, in unix seconds.                                                                                                                                    |
| `status`                | body | string                  | —      | Status is the lifecycle state, server-owned and never accepted from a caller.                                                                                                                   |
| `updatedAt`             | body | integer (int64)         | —      | UpdatedAt is the last write in unix seconds — an edit, a launch or a pause.                                                                                                                     |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo campaign create
```

**SDK**

**.ts**

```ts
import { Configuration, CampaignApi } from 'hanzoai';

const api = new CampaignApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postCampaign({ audience: "<audience>", budget: 0 });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import CampaignApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = CampaignApi(client).post_campaign(audience="<audience>", budget=0)
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.CampaignAPI.PostCampaign(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, campaign_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = campaign_api::post_campaign(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.CampaignApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new CampaignApi(client).postCampaign();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/campaign \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "audience": "<audience>",
       "budget": 0
     }'
```

**MCP**

MCP reaches **campaign** through the `campaign` tool, which names its 9 operations with its own verbs — this one among them, under a name only MCP declares. `describe` explains any of them:

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "list_campaigns"
         }
       }
     }'
```

---

[Campaign API](https://docs.hanzo.ai/docs/openapi/campaign) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
