News for Developers

Back to News
Scheduled Rules
Jordan Rogers-Smith
July 5, 2017

The Ad Rules engine is a central rule management service that helps you manage ads more easily, efficiently and intelligently. Typically you periodically query Marketing API to monitor the status of ads, and manually take action on certain conditions. Since most conditions can be quantified as logical expressions, we can automate this management.

Today the Schedule Based Rules API part of the Ad Rules engine is publically available.

Trigger Based Rules API remains in open beta. Please email rulesengine@fb.comwith your app ID to request access.

Schedule Based Rules are evaluated on a set interval i.e. DAILY, HOURLY and SEMI_HOURLY. At each interval the rule condition is checked if it is true and then one of 5 possible actions is taken. Schedule Based Rules are created in the Ad Rules Library act_xxxxxx/adrules_library and have three parts:

  • name - rules name,
  • evaluation_spec - determines objects to evaluate the rule against,
  • execution_spec- the action to be applied to the objects who pass the condition,

Below is an example of a schedule rule that runs once a day at midnight that pauses all Ads under the Ad Sets with ID 101, 102, or 103 that have had more than 10000 impressions in the last 7 days and have a CPC greater than $0.10.

curl \
-F 'name=Rule 1' \
-F 'evaluation_spec={
      "evaluation_type" : "SCHEDULE",
      "filters" : [
       {
         "field": "entity_type",
         "value": "AD",
         "operator": "EQUAL"
       },
       {
         "field": "time_preset",
         "value": "LAST_7_DAYS",
         "operator": "EQUAL"
       },
       {
         "field": "adset.id",
         "value": [101, 102, 103],
         "operator": "IN"
       },
       {
         "field": "impressions",
         "value": 10000,
         "operator": "GREATER_THAN"
       },
       {
         "field": "cpc",
         "value": 10,
         "operator": "GREATER_THAN"
       }
       
     ]
   }' \
-F 'execution_spec={
      "execution_type": "PAUSE"
   }' \
-F 'schedule_spec={
      "schedule_type": "DAILY"
   }' \
-F "access_token=<ACCESS_TOKEN>" \
https://graph.facebook.com/<VERSION>/<AD_ACCOUNT_ID>/adrules_library

To learn more about the different parameters and actions available for Schedule Based Rules, see here.


Related News

November 08 2017

November 07 2017

September 26 2017

September 20 2017

August 02 2017

July 10 2017