# Replace campaigns

URL: https://docs.hanzo.ai/docs/openapi/ad/put-ad-campaigns-by-id

> Replaces the user-owned fields of one of the caller org's campaigns and answers the stored row.

`PUT /v1/ad/campaigns/{id}`

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

|               |                                             |
| ------------- | ------------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/ad/campaigns/{id}` |
| **Method**    | `PUT`                                       |
| **Operation** | `put_ad_campaigns_by_id`                    |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`      |

Replaces the user-owned fields of one of the caller org's
campaigns and answers the stored row. It is a full replace, not a patch: every
field is written from the request, so an omitted one is cleared. externalId is
launch-owned and is never touched here, so editing a campaign cannot break its
link to a live provider execution.

## Request

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

| Field       | In   | Type            | Required | Description                                                                 |
| ----------- | ---- | --------------- | -------- | --------------------------------------------------------------------------- |
| `id`        | path | string          | yes      |                                                                             |
| `account`   | body | string          | —        | Account is the provider ad-account this campaign runs on (Meta act\_\<id>). |
| `budget`    | body | integer (int64) | —        | Budget is the campaign budget in MINOR units (cents).                       |
| `name`      | body | string          | —        | Name is the campaign's display label.                                       |
| `objective` | body | string          | —        | Objective is the campaign goal as the provider names it.                    |
| `platform`  | body | string          | —        | Platform is the ad network: meta, google, tiktok or x.                      |
| `spend`     | body | integer (int64) | —        | Spend is the amount spent so far in MINOR units (cents).                    |
| `status`    | body | string          | —        | Status is the lifecycle state: draft, active, paused or completed.          |

## Response

| Status    | Body            | Meaning |
| --------- | --------------- | ------- |
| `200`     | ad.AdCampaign   | ok      |
| `default` | problem-details | refused |

`200` body — 11 fields.

| Field        | In   | Type            | Always | Description                                                                                                                                                                                             |
| ------------ | ---- | --------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `account`    | body | string          | —      | Account is the provider ad-account the campaign runs under, in Meta's act\_\<id> form.                                                                                                                  |
| `budget`     | body | integer (int64) | —      | Budget is the campaign's authorized spend in MINOR units (cents).                                                                                                                                       |
| `createdAt`  | body | integer (int64) | —      | CreatedAt is when the campaign was first stored, in unix seconds.                                                                                                                                       |
| `externalId` | body | string          | —      | ExternalID is the ad network's own campaign id, written by a successful launch and by nothing else — an update never touches it.                                                                        |
| `id`         | body | string          | —      | ID is the campaign's server-minted handle, "camp\_" + 32 hex.                                                                                                                                           |
| `name`       | body | string          | —      | Name is the campaign's display label, and the name Meta creates the campaign object under at launch.                                                                                                    |
| `objective`  | body | string          | —      | Objective is the campaign goal spelled as the provider names it ("conversions", "OUTCOME\_TRAFFIC"), passed through to the network verbatim at launch — Meta defaults an empty one to OUTCOME\_TRAFFIC. |
| `platform`   | body | string          | —      | Platform is the ad network: meta, google, tiktok or x, and nothing else — a write naming another is 400.                                                                                                |
| `spend`      | body | integer (int64) | —      | Spend is spend-to-date in MINOR units (cents), as last written through create or update.                                                                                                                |
| `status`     | body | string          | —      | Status is the lifecycle: draft, active, paused or completed, and nothing else — a write naming another is 400.                                                                                          |
| `updatedAt`  | body | integer (int64) | —      | UpdatedAt is when the row was last written, in unix seconds — set by create, update and launch.                                                                                                         |

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

## Examples

**CLI**

```bash
hanzo ad campaigns set <id>
```

**SDK**

**.ts**

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

const api = new AdApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.putAdCampaignsById({ id: 'id', account: "<account>", budget: 0 });
```

**.py**

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

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = AdApi(client).put_ad_campaigns_by_id(id='id', account="<account>", budget=0)
```

**.go**

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

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

**.rs**

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

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

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

**.java**

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

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

var result = new AdApi(client).putAdCampaignsById();
```

**HTTP**

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

**MCP**

MCP reaches **ad** through the `ad` tool, which names its 6 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_ad_campaigns"
         }
       }
     }'
```

---

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