# Create a Meta Ads campaign from an agent

Creating a Meta Ads campaign takes two calls: `ads.validateCampaignPlan`, a dry run, then `ads.createCampaignPlan`, which leaves `status: PAUSED` on the campaign, ad set, and ad. A signed-in workspace owner activates it in the web app; MCP refuses.

## What PubNio supports in a Meta plan

Beyond a name, an objective, and a budget, a Meta plan needs:

- `targets[].actorAccountId`: the connected Facebook Page the ad runs as; Meta receives its ID as `page_id`. Without it the dry run answers `actor_required`.
- `adGroups[].targeting.geo_locations` with at least one country, region, city, or zip; without it the dry run answers `targeting_invalid`.
- `creative.destinationUrl` on every ad; without it the dry run answers `destination_required`.
- `creative.providerSettings.imageHash` on every ad; without it the dry run answers `image_required`.

| Plan objective | Meta receives |
| --- | --- |
| awareness, reach, video_views | `OUTCOME_AWARENESS` |
| traffic | `OUTCOME_TRAFFIC` |
| leads | `OUTCOME_LEADS` |
| sales, conversions | `OUTCOME_SALES` |
| app_promotion | `OUTCOME_APP_PROMOTION` |
| engagement, unknown | `OUTCOME_ENGAGEMENT` |

## Spend controls

- `ads.validateCampaignPlan` compiles the plan and checks account readiness, capabilities, budget, currency, and the spend policy without calling the provider.
- Activating a campaign takes `confirmation: "activate_spend"` from a signed-in workspace owner in the web app; an API key or an MCP session gets 403 `human_actor_required`.

## 1. Validate the plan (dry run)

```http
POST /api/v1/ads/campaigns/validate?workspaceId=3d9a1f20-7c4b-4e8a-9f61-2b5c8d7e0a14
Authorization: Bearer <token>
Content-Type: application/json

{
  "name": "Trail shoe engagement",
  "objective": "engagement",
  "budget": {
    "amountMinor": 4000,
    "currency": "USD",
    "kind": "daily"
  },
  "targets": [
    {
      "accountId": "7f3c2a10-5b4e-4d6f-8a9b-0c1d2e3f4a5b",
      "actorAccountId": "2b8d9e10-4c5f-4a6b-9c7d-8e9f0a1b2c3d"
    }
  ],
  "adGroups": [
    {
      "name": "Trail runners, US and Canada",
      "targeting": {
        "geo_locations": {
          "countries": [
            "US",
            "CA"
          ]
        }
      },
      "ads": [
        {
          "name": "Grip on wet rock",
          "creative": {
            "headline": "Grip on wet rock",
            "body": "Lugged soles for muddy switchbacks.",
            "callToAction": "SHOP_NOW",
            "destinationUrl": "https://shop.example.com/trail",
            "providerSettings": {
              "imageHash": "8f3a1c9e2b7d4f60"
            }
          }
        }
      ]
    }
  ]
}
```

A ready account gets 200 with `valid: true` and no issues. Meta's adapter checks every draft locally first.

## 2. Create it paused

Send the same plan with `Idempotency-Key: plan-meta-ads-1`: PubNio answers 202 `queued`, and `ads.getOperation` reports when every level exists paused. The same key with the same plan returns the same `planId`; with another plan it gets 400 `idempotency_conflict`.

## Limits

- A plan uploads no media: the `imageHash` names an image already in the ad account, and a media URL is refused with `media_requires_import`.

## Related

- [Meta Ads through PubNio](https://pubnio.com/ads/meta-ads)
- [All ad providers](https://pubnio.com/ads)
- API reference: [ads.createCampaignPlan](https://pubnio.com/docs/reference/ads-create-campaign-plan/)

