# Update campaign

> Change a Meta campaign's name, budget, bid strategy or spend cap.

Canonical: <https://www.tryadeli.com/docs/api/ads/update-campaign>

`PATCH https://app.tryadeli.com/api/v1/ads/campaigns/{campaignId}`

Authorization: `Bearer <API key>` — see [Authentication](https://www.tryadeli.com/docs/authentication)

**Meta Ads.** Renames a campaign, or changes its Advantage campaign budget
(CBO), bid strategy or spend cap. Only the fields you send change. The campaign
must belong to `adAccountId`, or the response is `404 object_not_found`.

A campaign that budgets each ad set has no budget or bid strategy of its own:
sending either returns `400 invalid_request`, and they change on the ad set with
[Update ad group](https://www.tryadeli.com/docs/api/ads/update-ad-group). A budget keeps the type the
campaign has, because Meta does not switch daily and lifetime budgets.

**Body**

| Name                 | Type             | Required | Description                                                                                                        |
| -------------------- | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------ |
| `adAccountId`        | `string`         | Yes      | The ad account the campaign belongs to.                                                                            |
| `name`               | `string`         |          | Shown in Ads Manager.                                                                                              |
| `budget`             | `object`         |          | { type: daily \| lifetime, amount } in whole currency units. CBO campaigns only.                                   |
| `bidStrategy`        | `string`         |          | lowest\_cost, bid\_cap, cost\_cap or min\_roas. CBO campaigns only; amounts and ROAS floors stay on each ad set.   |
| `spendCap`           | `number \| null` |          | Whole currency units: the most the campaign may ever spend. null removes the cap. Meta's minimum is about 100 USD. |
| `confirmLargeChange` | `boolean`        |          | true once the user has confirmed a budget increase of more than 50%.                                               |

Raising a budget on a running campaign spends more as soon as Meta applies it.

## Limits on changes

Adeli paces Meta Ads changes so an ad account driven by an agent does not look
automated to Meta:

- Changes to one ad account are spaced a couple of seconds apart. When too many
  are queued, the response is `429 ads_change_limited` with `Retry-After`.
- A status or budget equal to the current one succeeds without calling Meta.
- One object's status, or its budget, can change four times an hour. The fifth
  change answers `429 ads_change_limited`.
- A budget increase of more than 50% answers `409 confirmation_required` with
  the old and new amounts. Confirm the amount with the user, then send it again
  with `confirmLargeChange: true`. Decreases are never held back.
- `422 ads_writes_paused` means Adeli has paused ad changes for the workspace.

## Request examples

**cURL**

```bash
curl -X PATCH "https://app.tryadeli.com/api/v1/ads/campaigns/120210000000000001?accountId=00000000-0000-0000-0000-000000000000" \
  -H "Authorization: Bearer $ADELI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "adAccountId": "act_1234567890",
  "budget": {
    "type": "daily",
    "amount": 40
  }
}'
```

**JavaScript**

```javascript
const response = await fetch("https://app.tryadeli.com/api/v1/ads/campaigns/120210000000000001?accountId=00000000-0000-0000-0000-000000000000", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.ADELI_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    adAccountId: "act_1234567890",
    budget: {
      type: "daily",
      amount: 40,
    },
  }),
});
console.log(await response.json());
```

**Python**

```python
import os

import requests

response = requests.patch(
    "https://app.tryadeli.com/api/v1/ads/campaigns/120210000000000001",
    headers={"Authorization": f"Bearer {os.environ['ADELI_API_KEY']}"},
    params={
        "accountId": "00000000-0000-0000-0000-000000000000",
    },
    json={
        "adAccountId": "act_1234567890",
        "budget": {
            "type": "daily",
            "amount": 40,
        },
    },
)
print(response.json())
```

## Responses

### 200

```json
{
  "platform": "meta_ads",
  "accountId": "00000000-0000-0000-0000-000000000000",
  "adAccountId": "act_1234567890",
  "campaign": { "campaignId": "120210000000000001", "updated": ["budget"] }
}
```

### 400

```json
{
  "error": {
    "code": "invalid_request",
    "message": "This campaign budgets each ad set; change the budget or bid on the ad set"
  }
}
```
