# Create a campaign

Create an X Ads campaign from ad text, a link and an optional website card, in one call.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

`POST /v1/ads/create` publishes a promoted-only post and builds the campaign, line item and promoted post around it. The post is hidden from the organic timeline and shown only as an ad.

## Create a campaign

Zernio publishes the post as the ad account's full promotable user. `body` carries the post text, at most 280 characters.

A `linkUrl` on its own is appended to the text, and X counts it as about 24 characters because it shortens the link. Add `imageUrl` and `headline` to show it as a [website card](#website-card) instead.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
import Zernio from '@zernio/node';

const zernio = new Zernio();

const { data: created } = await zernio.adcampaigns.createStandaloneAd({
  body: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    adAccountId: '18ce54d4x5t',
    name: 'Q2 product awareness',
    goal: 'awareness',
    budgetAmount: 75,
    budgetType: 'daily',
    body: 'Ship faster with platform engineering done right.',
    linkUrl: 'https://example.com/platform',
    countries: ['US']
  }
});

console.log(created.ad.platformAdSetId);
```
</Tab>
<Tab value="Python">
```python
from zernio import Zernio

client = Zernio()

created = client.ad_campaigns.create_standalone_ad(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    ad_account_id="18ce54d4x5t",
    name="Q2 product awareness",
    goal="awareness",
    budget_amount=75,
    budget_type="daily",
    body="Ship faster with platform engineering done right.",
    link_url="https://example.com/platform",
    countries=["US"],
)

print(created["ad"]["platformAdSetId"])
```
</Tab>
<Tab value="curl">
```bash
curl -X POST "https://zernio.com/api/v1/ads/create" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
    "adAccountId": "18ce54d4x5t",
    "name": "Q2 product awareness",
    "goal": "awareness",
    "budgetAmount": 75,
    "budgetType": "daily",
    "body": "Ship faster with platform engineering done right.",
    "linkUrl": "https://example.com/platform",
    "countries": ["US"]
  }'
```
</Tab>
</Tabs>

Response (`201`):

```json
{
  "ad": {
    "_id": "66f0a1b2c3d4e5f6a7b8c9d0",
    "name": "Q2 product awareness",
    "platform": "twitter",
    "status": "pending_review",
    "adType": "standalone",
    "goal": "awareness",
    "budget": { "amount": 75, "type": "daily" },
    "platformAdId": "5gzhb",
    "platformCampaignId": "f4x8j",
    "platformAdSetId": "9r2mv"
  },
  "message": "Ad created"
}
```

`platformAdSetId` is the X line item. Every sample on the X Ads pages reuses the `zernio` and `client` constructors from this one.

`goal` takes `engagement`, `traffic`, `awareness`, `video_views` or `app_promotion`. The targeting fields are on [Targeting fields](/platforms/x-ads/targeting).

## Budget and schedule

`budgetAmount` is in whole currency units of the ad account, so `75` is $75.00 on a USD account.

`budgetType` is `daily` or `lifetime` and lands on the line item. A `lifetime` budget needs `endDate`, and `startDate` defaults to now.

`startDate` and `endDate` take ISO 8601 date-times with an offset. A value without an offset, date-only included, is read in the ad account's timezone, and a date-only `endDate` runs to 23:59:59 local.

## Website card

`imageUrl`, `headline` and `linkUrl` together build an X website card: the image, the `headline` as its title (at most 70 characters) and the destination under the post.

The URL is then not added to the post text, so `body` keeps all 280 characters. Zernio downloads `imageUrl` and uploads it to X, so it must be a public URL.

```bash
curl -X POST "https://zernio.com/api/v1/ads/create" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
    "adAccountId": "18ce54d4x5t",
    "name": "Q2 platform launch",
    "goal": "traffic",
    "budgetAmount": 500,
    "budgetType": "lifetime",
    "startDate": "2027-01-04T00:00:00+01:00",
    "endDate": "2027-01-31T23:59:59+01:00",
    "body": "Ship faster with platform engineering done right.",
    "imageUrl": "https://example.com/images/platform-card.png",
    "headline": "Platform engineering, done right",
    "linkUrl": "https://example.com/platform",
    "countries": ["US"]
  }'
```

`imageUrl` or `headline` without the other two returns `400`. A `linkUrl` alone is valid: it makes a plain post with the link appended.

## How it behaves

- `description`, `video` and `callToAction` have no slot on X and return `400`.
- To run an X ad with a video, [promote a post](/platforms/x-ads/boost) that already carries it, within [X's media limits](/platforms/twitter/media).
- After creation only status, budget and bid change ([Manage ads](/platforms/x-ads/manage-ads)).

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `422` with code `ads_connection_required` | The profile has no `xads` account | Run the [connect](/platforms/x-ads#connect) flow with the X posting account id. |
| `400` with code `missing_required_field` | `body` is absent, or a website card misses one of `imageUrl`, `headline` and `linkUrl` | Send the ad text, and all three card fields or none of them. |
| `400` with code `invalid_field_value` | A `goal` outside the 5 X values, text over 280 characters, a `headline` over 70, or `description`, `video` or `callToAction` | Use a supported goal, trim the text and drop the fields X has no slot for. |
| `403` with code `ads_allowance_exceeded` | No payment method on file and 500 live ads reached | Add a card to resume creating ads. |
| `502` with code `platform_api_error` | X rejected the request | Read `platformError` for X's own payload. |

## Related

- [Create standalone ad](/ad-campaigns/create-standalone-ad): every field of the request.
- [Targeting fields](/platforms/x-ads/targeting): locations, interests, audiences, age and language.
- [Promote a post](/platforms/x-ads/boost): run an existing post, video included, as an ad.
- [Manage ads](/platforms/x-ads/manage-ads): pause, rebudget and delete after creation.
- [Limits & Errors](/platforms/x-ads/reference): what X's Ads API does not expose.