# Create ads

Create an AppLovin app or web campaign with its first creative set in one call, or add a creative set to a campaign.

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

`POST /v1/ads/create` creates the campaign and its first creative set in one call. In AppLovin the creative set is the ad: a group of playable HTML, video and image assets.

## Create a campaign

This creates an iOS app campaign with a cost per install goal. Without `status`, it is created paused.

<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: '6507a1b2c3d4e5f6a7b8c9d0',
    adAccountId: '184520',
    name: 'Trail maps iOS',
    goal: 'app_promotion',
    budgetAmount: 50,
    budgetType: 'daily',
    countries: ['US', 'CA'],
    platformSpecificData: {
      campaignType: 'APP',
      os: 'IOS',
      packageName: 'com.meridian.trails',
      itunesId: 1234567890,
      goalType: 'CPI',
      goalValue: 2.5,
      tracking: {
        method: 'APPSFLYER',
        impressionUrl: 'https://impression.appsflyer.com/id1234567890?pid=applovin_int',
        clickUrl: 'https://app.appsflyer.com/id1234567890?pid=applovin_int'
      },
      assets: [
        { type: 'VID_LONG_P', url: 'https://cdn.example.com/trail-30s.mp4' },
        { type: 'IMG_INTER_P', url: 'https://cdn.example.com/trail-portrait.jpg' }
      ]
    }
  }
});

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

client = Zernio()

created = client.ad_campaigns.create_standalone_ad(
    account_id="6507a1b2c3d4e5f6a7b8c9d0",
    ad_account_id="184520",
    name="Trail maps iOS",
    goal="app_promotion",
    budget_amount=50,
    budget_type="daily",
    countries=["US", "CA"],
    platform_specific_data={
        "campaignType": "APP",
        "os": "IOS",
        "packageName": "com.meridian.trails",
        "itunesId": 1234567890,
        "goalType": "CPI",
        "goalValue": 2.5,
        "tracking": {
            "method": "APPSFLYER",
            "impressionUrl": "https://impression.appsflyer.com/id1234567890?pid=applovin_int",
            "clickUrl": "https://app.appsflyer.com/id1234567890?pid=applovin_int",
        },
        "assets": [
            {"type": "VID_LONG_P", "url": "https://cdn.example.com/trail-30s.mp4"},
            {"type": "IMG_INTER_P", "url": "https://cdn.example.com/trail-portrait.jpg"},
        ],
    },
)

print(created["ad"]["id"])
```
</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": "6507a1b2c3d4e5f6a7b8c9d0",
    "adAccountId": "184520",
    "name": "Trail maps iOS",
    "goal": "app_promotion",
    "budgetAmount": 50,
    "budgetType": "daily",
    "countries": ["US", "CA"],
    "platformSpecificData": {
      "campaignType": "APP",
      "os": "IOS",
      "packageName": "com.meridian.trails",
      "itunesId": 1234567890,
      "goalType": "CPI",
      "goalValue": 2.5,
      "tracking": {
        "method": "APPSFLYER",
        "impressionUrl": "https://impression.appsflyer.com/id1234567890?pid=applovin_int",
        "clickUrl": "https://app.appsflyer.com/id1234567890?pid=applovin_int"
      },
      "assets": [
        { "type": "VID_LONG_P", "url": "https://cdn.example.com/trail-30s.mp4" },
        { "type": "IMG_INTER_P", "url": "https://cdn.example.com/trail-portrait.jpg" }
      ]
    }
  }'
```
</Tab>
</Tabs>

Response (`201`), trimmed:

```json
{
  "ad": {
    "id": "6ae0968fa23091cc35b72188",
    "name": "Trail maps iOS",
    "platform": "applovin",
    "status": "paused",
    "goal": "app_promotion",
    "budget": { "amount": 50, "type": "daily" },
    "platformAdId": "9c41e07b2d",
    "platformCampaignId": "5f2a8d1c3e",
    "platformAdSetId": "5f2a8d1c3e",
    "platformAdAccountId": "184520"
  }
}
```

`platformCampaignId` is the campaign's hashed id, the value of the `{CAMPAIGN_ID}` macro. `platformAdSetId` repeats it, because AppLovin has no ad set. `platformAdId` is the creative set's hashed id.

The `accountId` is the account from [Connect](/platforms/applovin/connect), and `adAccountId` is its ad account from [List ad accounts](/ad-accounts/list-ad-accounts). Every sample on the AppLovin pages reuses the `zernio` and `client` constructors from this one.

## Create a web campaign

Send `campaignType: "WEB"` and the site in `linkUrl` (or `platformSpecificData.websiteUrl`).

`goal: "lead_generation"` sets a cost per event goal, counted on the event in `eventTarget`, and `goal: "conversions"` a cost per purchase goal.

```bash
curl -X POST "https://zernio.com/api/v1/ads/create" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "6507a1b2c3d4e5f6a7b8c9d0",
    "adAccountId": "184520",
    "name": "Trail guide trial",
    "goal": "lead_generation",
    "budgetAmount": 30,
    "budgetType": "daily",
    "linkUrl": "https://example.com/trial",
    "countries": ["US"],
    "platformSpecificData": {
      "campaignType": "WEB",
      "goalValue": 12,
      "eventTarget": "GENERATE_LEAD",
      "assets": [{ "type": "HOSTED_HTML", "url": "https://cdn.example.com/trial-playable.html" }]
    }
  }'
```

## Add a creative set to a campaign

Send `existingCampaignId` with the campaign's hashed id and the new creative set's `assets`. The campaign keeps its budget, goal and targeting.

```bash
curl -X POST "https://zernio.com/api/v1/ads/create" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "6507a1b2c3d4e5f6a7b8c9d0",
    "adAccountId": "184520",
    "existingCampaignId": "5f2a8d1c3e",
    "adName": "Trail maps playable",
    "platformSpecificData": {
      "assets": [{ "type": "HOSTED_HTML", "url": "https://cdn.example.com/trail-playable.html" }]
    }
  }'
```

To create a campaign without a creative set, send the same campaign fields, including `countries`, `regions`, `metros` and `platformSpecificData`, to `POST /v1/ads/campaigns`.

## Platform fields

Fields of `platformSpecificData`:

| Field | Rule |
|-------|------|
| `campaignType` | `APP` or `WEB`, required for a new campaign |
| `os` | `IOS` or `ANDROID`, required for `APP` |
| `packageName` | The app's package name or bundle id, required for `APP` |
| `itunesId` | The App Store id, a number, required for an iOS app |
| `websiteUrl` | An https URL, required for `WEB` unless you send `linkUrl` |
| `tracking` | `method` (`ADJUST`, `APPSFLYER`, `APSALAR`, `BRANCH`, `KOCHAVA` or `TENJIN`), `impressionUrl` and `clickUrl`, required for `APP` |
| `goalType` | `CPI`, `CPE`, `CPP`, `AD_ROAS`, `CHK_ROAS` or `BLD_ROAS`. A web campaign takes `CPE`, `CPP` or `CHK_ROAS`. Overrides the one `goal` sets |
| `goalValue` | The goal for every country. Send it or `countryGoalValues` |
| `countryGoalValues` | One goal per country, such as `{ "US": 2.5 }` |
| `roasDayTarget` | `DAY7` or `DAY28` for an app, `DAY0` or `DAY7` for a website. Required for ROAS goals and web `CPP` |
| `eventTarget` | The event a `CPE` goal counts, such as `GENERATE_LEAD`. Required for `CPE`, `lead_generation` included |
| `biddingStrategy` | `TARGET_GOAL_WITH_CPI_BILLING` (the default for `CPI`) or `AUTO_BIDDING_WITH_CPM_BILLING` (the default otherwise) |
| `countryBudgets` | One daily budget per country, such as `{ "US": 50, "CA": 20 }`, instead of `budgetAmount` |
| `audienceStrategy` | `UNIVERSAL`, `PROSPECTING` or `DISCOVERY`, for `WEB` |
| `assets` | `[{ "type", "url" }]` to upload, or `[{ "id" }]` for assets already in the account. Types: `HOSTED_HTML`, `VID_LONG_P`, `VID_SHORT_P`, `IMG_BANNER`, `IMG_INTER_P` |
| `languages` | The creative set's languages, such as `["ENGLISH"]`. All by default |
| `brandInfo` | For a web creative set: `title` (up to 25 characters), `description` (75), `buttonLabel` (13), `buttonColor` and `iconUrl`. Without it, the account's brand info applies |

Goal limits for an app: `CPI` under 200, `CPE` and `CPP` under 500, `AD_ROAS` at least 0.1, `CHK_ROAS` at least 0.01, `BLD_ROAS` at least 0.05.

## How it behaves

- The assets you upload need a `HOSTED_HTML`, or an `IMG_INTER_P` with a `VID_LONG_P` or `VID_SHORT_P`.
- `status` is `ACTIVE` or `PAUSED`, and `PAUSED` by default.
- `startDate` defaults to now and cannot be in the past. Without `endDate`, the campaign runs until you pause it.
- `validateOnly: true` runs every check and makes no AppLovin call.
- Zernio checks every field before calling AppLovin, which locks an account out for a day after 100 errors in 5 minutes.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `422` with `param: "budgetType"` | A lifetime budget | Send `budgetType: "daily"`. |
| `422` on `countries` | No countries sent | Send at least one country. |
| `422` on a `platformSpecificData` field | A required field is missing for the campaign type, or a goal is out of range | Fix the field the error names. |
| `400` with `invalid_field_value` on `POST /v1/ads/ad-sets` | AppLovin has no ad sets | Set budget, goal and targeting on the campaign. |

## Related

- [Create standalone ad](/ad-campaigns/create-standalone-ad): every field of the request.
- [Targeting](/platforms/applovin/targeting): countries, US states and metros.
- [Manage ads](/platforms/applovin/manage-ads): pause, resume, rebudget and remove.
- [Limits & errors](/platforms/applovin/reference): what AppLovin does not support yet.