# Ads recipes

Three ads jobs end to end: boost posts that take off, run always-on website retargeting and test three creatives against two audiences.

Three common ads jobs, each as the API calls that do it. Every example is created paused, so copying it spends nothing until you switch it on.

## Before you start

- **Ads add-on:** legacy plans need it; usage-based plans include it.
- **Meta:** these recipes run on a Meta ads connection. `accountId` is that connection and `adAccountId` starts with `act_`.
- **Automations:** read the [automations guide](/guides/automations) for triggers, filters and limits.

## Boost the posts that take off

A scheduled automation checks the profile's recent posts every hour and boosts each one past 1,000 likes or 100 comments, once. The full step reference is in [boost posts that take off](/guides/automations#boost-posts-that-take-off).

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

const zernio = new Zernio();

const { data } = await zernio.automations.createAutomation({
  body: {
    name: 'Boost winners',
    status: 'paused',
    trigger: { type: 'schedule', every: '1h' },
    subjects: { each: 'post', profileId: '6731a0c2e4b0f1a2b3c4d5e6', publishedWithin: '3d' },
    filter: {
      any: [
        { field: 'likes', op: 'greater_than', value: 1000 },
        { field: 'comments', op: 'greater_than', value: 100 },
      ],
    },
    steps: [
      { type: 'ads.boost_post', adAccountId: 'act_1234567890', budget: 50, days: 5, goal: 'engagement', countries: ['US', 'CA'] },
    ],
    limits: { maxChangesPerDay: 3 },
  },
});

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

client = Zernio()

created = client.automations.create_automation(
    body={
        "name": "Boost winners",
        "status": "paused",
        "trigger": {"type": "schedule", "every": "1h"},
        "subjects": {"each": "post", "profileId": "6731a0c2e4b0f1a2b3c4d5e6", "publishedWithin": "3d"},
        "filter": {
            "any": [
                {"field": "likes", "op": "greater_than", "value": 1000},
                {"field": "comments", "op": "greater_than", "value": 100},
            ],
        },
        "steps": [
            {"type": "ads.boost_post", "adAccountId": "act_1234567890", "budget": 50, "days": 5, "goal": "engagement", "countries": ["US", "CA"]},
        ],
        "limits": {"maxChangesPerDay": 3},
    },
)

print(created["automation"]["id"])
```
</Tab>
<Tab value="curl">
```bash
curl -X POST "https://zernio.com/api/v1/automations" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Boost winners",
    "status": "paused",
    "trigger": { "type": "schedule", "every": "1h" },
    "subjects": { "each": "post", "profileId": "6731a0c2e4b0f1a2b3c4d5e6", "publishedWithin": "3d" },
    "filter": {
      "any": [
        { "field": "likes", "op": "greater_than", "value": 1000 },
        { "field": "comments", "op": "greater_than", "value": 100 }
      ]
    },
    "steps": [
      { "type": "ads.boost_post", "adAccountId": "act_1234567890", "budget": 50, "days": 5, "goal": "engagement", "countries": ["US", "CA"] }
    ],
    "limits": { "maxChangesPerDay": 3 }
  }'
```
</Tab>
</Tabs>

- Only Facebook and Instagram posts are boosted. Posts on other platforms are skipped.
- `budget` is the whole spend of one boost, in the ad account currency.
- `limits.maxChangesPerDay` (up to 20) is required, and at most 5 posts are boosted per check.
- `GET /v1/automations/catalog` lists every post fact a `filter` can compare, such as `shares`, `views` and `engagementRate`.

Switch it on with `PATCH /v1/automations/{automationId}` and `{ "status": "active" }`.

**Run it from n8n, Make or Zapier.** Create it once from an HTTP request with the same body: see [n8n](/resources/integrations/n8n), [Make](/resources/integrations/make) and [Zapier](/resources/integrations/zapier). The automation then runs on Zernio's schedule, with no workflow left running.

<CopyPrompt title="Ask your agent" prompt="Create a paused Zernio automation that checks my profile's posts every hour and boosts each Facebook or Instagram post past 1,000 likes with a 50 budget for 5 days in the US, at most 3 a day." />

## Run always-on website retargeting

Create a website audience from your Meta Pixel, then an ad that targets it with a daily budget and no `endDate`. A daily budget with no end runs until you pause it.

Find the pixel id with `GET /v1/accounts/{accountId}/tracking-tags` ([pixels guide](/guides/pixels)). `retentionDays` is at most 180 on Meta, and `urlContains` keeps only visitors of matching pages.

<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.adaudiences.createAdAudience({
  body: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    adAccountId: 'act_1234567890',
    type: 'website',
    name: 'Pricing visitors, 30 days',
    pixelId: '1234567890123456',
    retentionDays: 30,
    urlContains: '/pricing',
  },
});

const { data: ad } = await zernio.adcampaigns.createStandaloneAd({
  body: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    adAccountId: 'act_1234567890',
    name: 'Retarget pricing visitors',
    goal: 'traffic',
    budgetAmount: 20,
    budgetType: 'daily',
    status: 'PAUSED',
    audienceId: created.audience.platformAudienceId,
    countries: ['US'],
    headline: 'Still deciding?',
    body: 'Start your free trial today.',
    imageUrl: 'https://cdn.example.com/retarget.jpg',
    linkUrl: 'https://example.com/pricing',
    callToAction: 'SIGN_UP',
  },
});
```
</Tab>
<Tab value="Python">
```python
from zernio import Zernio

client = Zernio()

created = client.ad_audiences.create_ad_audience(
    body={
        "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
        "adAccountId": "act_1234567890",
        "type": "website",
        "name": "Pricing visitors, 30 days",
        "pixelId": "1234567890123456",
        "retentionDays": 30,
        "urlContains": "/pricing",
    },
)

ad = client.ad_campaigns.create_standalone_ad(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    ad_account_id="act_1234567890",
    name="Retarget pricing visitors",
    goal="traffic",
    budget_amount=20,
    budget_type="daily",
    status="PAUSED",
    audience_id=created["audience"]["platformAudienceId"],
    countries=["US"],
    headline="Still deciding?",
    body="Start your free trial today.",
    image_url="https://cdn.example.com/retarget.jpg",
    link_url="https://example.com/pricing",
    call_to_action="SIGN_UP",
)
```
</Tab>
<Tab value="curl">
```bash
curl -X POST "https://zernio.com/api/v1/ads/audiences" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
    "adAccountId": "act_1234567890",
    "type": "website",
    "name": "Pricing visitors, 30 days",
    "pixelId": "1234567890123456",
    "retentionDays": 30,
    "urlContains": "/pricing"
  }'

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": "act_1234567890",
    "name": "Retarget pricing visitors",
    "goal": "traffic",
    "budgetAmount": 20,
    "budgetType": "daily",
    "status": "PAUSED",
    "audienceId": "6123456789",
    "countries": ["US"],
    "headline": "Still deciding?",
    "body": "Start your free trial today.",
    "imageUrl": "https://cdn.example.com/retarget.jpg",
    "linkUrl": "https://example.com/pricing",
    "callToAction": "SIGN_UP"
  }'
```
</Tab>
</Tabs>

`audienceId` takes the audience's `platformAudienceId`, the Meta id, not Zernio's `audience.id`. `budgetAmount` is in whole currency units: `20` is 20 a day in the ad account's currency.

`status: PAUSED` holds the new campaign with its ad set and ad on. Resume it with `PUT /v1/ads/campaigns/{campaignId}/status`, passing `ad.platformCampaignId` ([pause or resume](/platforms/meta-ads/manage-ads#pause-or-resume)).

**Run it from n8n, Make or Zapier.** Send both calls as HTTP requests with the same bodies, the second using the first one's `platformAudienceId`: see [n8n](/resources/integrations/n8n), [Make](/resources/integrations/make) and [Zapier](/resources/integrations/zapier).

<CopyPrompt title="Ask your agent" prompt="Create a Meta website audience of people who visited /pricing in the last 30 days from my pixel, then a paused traffic ad targeting it with a 20 a day budget and no end date." />

## Test 3 creatives against 2 audiences

Send `creatives[]` (Meta only) to build one campaign, one ad set and one ad per creative. Then send the same creatives with `existingCampaignId` and the second audience to add a second ad set.

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

const zernio = new Zernio();

const creatives = ['hook-1', 'hook-2', 'hook-3'].map((hook) => ({
  name: `Spring - ${hook}`,
  headline: 'Spring, 30% off',
  body: 'Limited time.',
  imageUrl: `https://cdn.example.com/${hook}.jpg`,
  linkUrl: 'https://example.com/spring',
  callToAction: 'SHOP_NOW',
}));

const shared = {
  accountId: '66b2e19d8c3f5a7e9d0b1c2d',
  adAccountId: 'act_1234567890',
  name: 'Spring',
  goal: 'traffic',
  budgetAmount: 30,
  budgetType: 'daily',
  status: 'PAUSED',
  countries: ['US'],
  creatives,
};

const { data: first } = await zernio.adcampaigns.createStandaloneAd({
  body: { ...shared, campaignName: 'Spring test', adSetName: 'Audience A', audienceId: '6123456789' },
});

await zernio.adcampaigns.createStandaloneAd({
  body: { ...shared, existingCampaignId: first.platformCampaignId, adSetName: 'Audience B', audienceId: '6987654321' },
});
```
</Tab>
<Tab value="Python">
```python
from zernio import Zernio

client = Zernio()

creatives = [
    {
        "name": f"Spring - {hook}",
        "headline": "Spring, 30% off",
        "body": "Limited time.",
        "imageUrl": f"https://cdn.example.com/{hook}.jpg",
        "linkUrl": "https://example.com/spring",
        "callToAction": "SHOP_NOW",
    }
    for hook in ["hook-1", "hook-2", "hook-3"]
]

shared = dict(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    ad_account_id="act_1234567890",
    name="Spring",
    goal="traffic",
    budget_amount=30,
    budget_type="daily",
    status="PAUSED",
    countries=["US"],
    creatives=creatives,
)

first = client.ad_campaigns.create_standalone_ad(
    **shared, campaign_name="Spring test", ad_set_name="Audience A", audience_id="6123456789",
)

client.ad_campaigns.create_standalone_ad(
    **shared, existing_campaign_id=first["platformCampaignId"], ad_set_name="Audience B", audience_id="6987654321",
)
```
</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": "act_1234567890",
    "name": "Spring",
    "goal": "traffic",
    "budgetAmount": 30,
    "budgetType": "daily",
    "status": "PAUSED",
    "countries": ["US"],
    "existingCampaignId": "120250000000000000",
    "adSetName": "Audience B",
    "audienceId": "6987654321",
    "creatives": [
      { "name": "Spring - hook-1", "headline": "Spring, 30% off", "body": "Limited time.", "imageUrl": "https://cdn.example.com/hook-1.jpg", "linkUrl": "https://example.com/spring", "callToAction": "SHOP_NOW" },
      { "name": "Spring - hook-2", "headline": "Spring, 30% off", "body": "Limited time.", "imageUrl": "https://cdn.example.com/hook-2.jpg", "linkUrl": "https://example.com/spring", "callToAction": "SHOP_NOW" },
      { "name": "Spring - hook-3", "headline": "Spring, 30% off", "body": "Limited time.", "imageUrl": "https://cdn.example.com/hook-3.jpg", "linkUrl": "https://example.com/spring", "callToAction": "SHOP_NOW" }
    ]
  }'
```
</Tab>
</Tabs>

The curl call is the second one: the first is the same body with `campaignName` and audience A instead of `existingCampaignId`. Its answer carries `platformCampaignId`, which the second call takes.

- The budget sits on each ad set, so each audience gets its own `budgetAmount`.
- `status: PAUSED` holds the new campaign on the first call and only the new ad set on the second. Resume both with the status calls in [pause or resume](/platforms/meta-ads/manage-ads#pause-or-resume).

**Run it from n8n, Make or Zapier.** Send both calls as HTTP requests with the same bodies, the second using the first one's `platformCampaignId`: see [n8n](/resources/integrations/n8n), [Make](/resources/integrations/make) and [Zapier](/resources/integrations/zapier).

<CopyPrompt title="Ask your agent" prompt="Create a paused Meta traffic campaign that tests these 3 images against my two saved audiences, one ad set per audience with a 30 a day budget each and one ad per image." />

## Related

- [Automations](/guides/automations): every trigger, filter and limit.
- [Meta custom audiences](/platforms/meta-ads/audiences): website, customer list and lookalike audiences.
- [Meta creative testing](/platforms/meta-ads/creative-testing): bigger creative matrices and how to read the winners.
- [Pixels and tracking tags](/guides/pixels): find and install the pixel a website audience reads.