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.
Authorization
bearerAuth 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" }}