Zernio
APIFor you
Zernio
APIFor you
API Reference

Automated Rules

Rules

List ad rulesGETCreate an ad rulePOSTGet an ad ruleGETUpdate an ad rulePATCHDelete an ad ruleDELETE

Preview and History

Preview an ad rulePOSTList an ad rule's runsGET
Dashboard
OverviewPlatformsAPI ReferenceResources
Automated Rules

Create an ad rule

Creates a rule that checks the campaigns or ad sets of one ad account on a schedule and acts on each one that meets every condition.

Rules support Meta, Google, TikTok, LinkedIn, Pinterest, X and Reddit ads connections. Each campaign or ad set is evaluated on its own, over the ad account's calendar days, from the metrics Zernio syncs. A rule can notify (the ad_rule.triggered webhook), and take at most one of pause, activate and adjust_budget. After acting on an object, the rule leaves that object alone for cooldownMinutes; a rule that pauses, activates or adjusts budgets needs a cooldown at least as long as its schedule.

activate only reactivates objects a rule paused, never ones you paused yourself, and only once the cooldown has passed since that pause. If you reactivate and pause such an object yourself between two runs of a rule, Zernio cannot tell your pause from the rule's, and an activate rule may reactivate it.

Use POST /v1/ads/rules/{ruleId}/preview to see what a rule would match before enabling it.


PlatformsMetaGoogleTikTokLinkedInPinterestX
POST
/v1/ads/rules

Authorization

bearerAuth
AuthorizationBearer <token>

API key authentication: send your Zernio API key in the Authorization header, prefixed with Bearer.

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

import Zernio from '@zernio/node';const zernio = new Zernio({ apiKey: process.env.ZERNIO_API_KEY });const { data } = await zernio.adrules.createAdRule({  body: {    name: 'Example',    accountId: 'account_abc123',    adAccountId: 'adaccount_abc123',    level: 'campaign',    conditions: {      all: [        {          metric: 'spend',          window: 'today',          op: '>',          value: 0,        },      ],    },    actions: [      {        type: 'notify',      },    ],  },});console.log(data);
{  "rule": {    "id": "string",    "name": "string",    "accountId": "string",    "platform": "string",    "adAccountId": "string",    "level": "campaign",    "campaignIds": [      "string"    ],    "conditions": {      "all": [        {          "metric": "spend",          "window": "today",          "op": ">",          "value": 0        }      ]    },    "actions": [      {        "type": "notify"      }    ],    "schedule": {      "everyMinutes": 60    },    "cooldownMinutes": 0,    "enabled": true,    "lastRunAt": "2019-08-24T14:15:22Z",    "nextRunAt": "2019-08-24T14:15:22Z",    "createdAt": "2019-08-24T14:15:22Z",    "updatedAt": "2019-08-24T14:15:22Z"  }}
Was this page helpful?

List ad rules

Lists the ad rules on the profiles your key can reach, newest first.

Get an ad rule

Returns one ad rule.

name*string
Length1 <= length <= 200
accountId*string

The ads connection (account ID from GET /v1/accounts).

adAccountId*string

Platform ad account ID, from GET /v1/ads/accounts.

level*AdRuleLevel

Whether the rule checks campaigns or ad sets. Each one is evaluated on its own.

Value in

  • "campaign"
  • "adset"
campaignIds?array<string>

Only check these platform campaign IDs (or their ad sets). Leave out to check the whole ad account.

Items1 <= items <= 100
conditions*

Every condition must hold for an object to match. A rate with no denominator (a CPA with no conversions) never matches.

actions*array<|||>

Each type at most once, and at most one of pause, activate and adjust_budget.

Items1 <= items
schedule?

Leave it out to run every 60 minutes.

cooldownMinutes?integer

How long the rule leaves an object alone after acting on it.

Range0 <= value <= 43200
Default1440
enabled?boolean
Defaulttrue