# Add new ad rule

| Value for parameter | Type   | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name                | String | Yes      | Ad Rules Library and minimally contain a `name`                                                                                                                                                                                                                                                                                                                                                            |
| status              | String | Yes      | <p>The status of a rule determines whether the rule should be running. There are two statuses: ENABLED and DISABLED. To temporarily turn off a rule, edit the rule and set its status to DISABLED. To reactivate a rule, edit the rule and set its status back to ENABLED. To permanently remove a rule, delete it.</p><p></p><p>Param status must be one of {ENABLED, DISABLED, DELETED, HAS\_ISSUES}</p> |
|                     |        |          |                                                                                                                                                                                                                                                                                                                                                                                                            |
|                     |        |          |                                                                                                                                                                                                                                                                                                                                                                                                            |

<table><thead><tr><th>Value for parameter `Evaluation Spec`</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>evaluation_type</td><td>String</td><td><p>The evaluation_type determines the type of evaluation method and has the following options: SCHEDULE,</p><p>TRIGGER</p></td></tr><tr><td>filters</td><td>Array</td><td><p>The filters array contains a list of filter objects. These objects are dictionaries with keys of field, value, and operator:</p><p></p><p><strong>Field must be a valid Insights filter</strong></p><p></p><p>Example : </p><pre><code>"filters": [
  {
    "field": "lifetime_impressions",
    "value": "8000",
    "operator": "GREATER_THAN"
  },
  {
    "field": "cost_per",
    "value": "10",
    "operator": "GREATER_THAN"
  },
  {
    "field": "entity_type",
    "value": "CAMPAIGN",
    "operator": "EQUAL"
  },
  {
    "field": "time_preset",
    "value": "MAXIMUM",
    "operator": "EQUAL"
  }
]

</code></pre></td></tr></tbody></table>

Below is a list of Insights filters and whether they are supported by Trigger Based Rules:

<table><thead><tr><th width="281">Value for parameter `Field`</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>mobile_app_purchase_roas</td><td>String</td><td></td></tr><tr><td>website_purchase_roas</td><td></td><td></td></tr><tr><td>impressions</td><td></td><td></td></tr><tr><td>unique_impressions</td><td></td><td></td></tr><tr><td>clicks</td><td></td><td></td></tr><tr><td>unique_clicks</td><td></td><td></td></tr><tr><td>spent</td><td></td><td></td></tr><tr><td>results</td><td></td><td></td></tr><tr><td>cost_per</td><td></td><td></td></tr><tr><td>cpc</td><td></td><td></td></tr><tr><td>cpm</td><td></td><td></td></tr><tr><td>ctr</td><td></td><td></td></tr><tr><td>cpa</td><td></td><td></td></tr><tr><td>cpp</td><td></td><td></td></tr><tr><td>reach</td><td></td><td></td></tr><tr><td>frequency</td><td></td><td></td></tr><tr><td>leadgen</td><td></td><td></td></tr><tr><td>link_ctr</td><td></td><td></td></tr><tr><td>cost_per_unique_click</td><td></td><td></td></tr><tr><td>result_rate</td><td></td><td></td></tr><tr><td>mobile_app_install</td><td></td><td></td></tr><tr><td>cost_per_mobile_app_install</td><td></td><td></td></tr><tr><td>app_custom_event</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_achievement_unlocked</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_activate_app</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_add_payment_info</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_add_to_cart</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_add_to_wishlist</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_complete_registration</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_content_view</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_initiated_checkout</td><td></td><td></td></tr><tr><td><br>app_custom_event.fb_mobile_level_achieved</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_purchase</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_rate</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_search</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_spent_credits</td><td></td><td></td></tr><tr><td>app_custom_event.fb_mobile_tutorial_completion</td><td></td><td></td></tr><tr><td>app_custom_event.other</td><td></td><td></td></tr><tr><td>cost_per_mobile_achievement_unlocked</td><td></td><td></td></tr><tr><td>cost_per_mobile_activate_app</td><td></td><td></td></tr><tr><td>cost_per_mobile_add_payment_info</td><td></td><td></td></tr><tr><td>cost_per_mobile_complete_registration</td><td></td><td></td></tr><tr><td>cost_per_mobile_content_view</td><td></td><td></td></tr><tr><td>cost_per_mobile_initiated_checkout</td><td></td><td></td></tr><tr><td>cost_per_mobile_level_achieved</td><td></td><td></td></tr><tr><td>cost_per_mobile_purchase</td><td></td><td></td></tr><tr><td>cost_per_mobile_rate</td><td></td><td></td></tr><tr><td>cost_per_mobile_search</td><td></td><td></td></tr><tr><td>cost_per_mobile_spent_credits</td><td></td><td></td></tr><tr><td>cost_per_mobile_tutorial_completion</td><td></td><td></td></tr><tr><td>offline_conversion</td><td></td><td></td></tr><tr><td>offline_conversion.add_payment_info</td><td></td><td></td></tr><tr><td>offline_conversion.add_to_cart</td><td></td><td></td></tr><tr><td>offline_conversion.add_to_wishlist</td><td></td><td></td></tr><tr><td>offline_conversion.complete_registration</td><td></td><td></td></tr><tr><td>offline_conversion.initiate_checkout</td><td></td><td></td></tr><tr><td>offline_conversion.lead</td><td></td><td></td></tr><tr><td>offline_conversion.other</td><td></td><td></td></tr><tr><td>offline_conversion.purchase</td><td></td><td></td></tr><tr><td>offline_conversion.search</td><td></td><td></td></tr><tr><td>offline_conversion.view_content</td><td></td><td></td></tr><tr><td>cost_per_offline_conversion</td><td></td><td></td></tr><tr><td>cost_per_offline_other</td><td></td><td></td></tr><tr><td>offsite_conversion</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_add_payment_info</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_add_to_cart</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_add_to_wishlist</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_complete_registration</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_initiate_checkout</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_lead</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_purchase</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_search</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_view_content</td><td></td><td></td></tr><tr><td>offsite_conversion.fb_pixel_other</td><td></td><td></td></tr><tr><td>cost_per_add_payment_info_fb</td><td></td><td></td></tr><tr><td>cost_per_add_to_cart_fb</td><td></td><td></td></tr><tr><td>cost_per_add_to_wishlist_fb</td><td></td><td></td></tr><tr><td>cost_per_complete_registration_fb</td><td></td><td></td></tr><tr><td>cost_per_initiate_checkout_fb</td><td></td><td></td></tr><tr><td>cost_per_lead_fb</td><td></td><td></td></tr><tr><td>cost_per_purchase_fb</td><td></td><td></td></tr><tr><td>cost_per_search_fb</td><td></td><td></td></tr><tr><td>cost_per_view_content_fb</td><td></td><td></td></tr><tr><td>link_click</td><td></td><td></td></tr><tr><td>cost_per_link_click</td><td></td><td></td></tr><tr><td>like</td><td></td><td></td></tr><tr><td>offsite_engagement</td><td></td><td></td></tr><tr><td>post</td><td></td><td></td></tr><tr><td>post_comment</td><td></td><td></td></tr><tr><td>post_engagement</td><td></td><td></td></tr><tr><td>cost_per_post_engagement</td><td></td><td></td></tr><tr><td>post_like</td><td></td><td></td></tr><tr><td>post_reaction</td><td></td><td></td></tr><tr><td>view_content</td><td></td><td></td></tr><tr><td>video_play</td><td></td><td></td></tr><tr><td>vote</td><td></td><td></td></tr><tr><td>unique_clicks</td><td></td><td></td></tr><tr><td>reach</td><td></td><td></td></tr><tr><td>lifetime_impressions</td><td></td><td></td></tr><tr><td>lifetime_spent</td><td></td><td></td></tr><tr><td>today_spent</td><td></td><td></td></tr><tr><td>yesterday_spent</td><td></td><td></td></tr></tbody></table>

<table><thead><tr><th>Value for parameter `Execution Spec`</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>execution_type</td><td>String</td><td>must be one of the following values: PING_ENDPOINT, NOTIFICATION, PAUSE, REBALANCE_BUDGET, CHANGE_BUDGET, CHANGE_BID, ROTATE, UNPAUSE, CHANGE_CAMPAIGN_BUDGET, ADD_INTEREST_RELAXATION, ADD_QUESTIONNAIRE_INTERESTS, INCREASE_RADIUS, UPDATE_CREATIVE, UPDATE_LAX_BUDGET, UPDATE_LAX_DURATION, AUDIENCE_CONSOLIDATION, AUDIENCE_CONSOLIDATION_ASK_FIRST</td></tr><tr><td>execution_options</td><td>Array</td><td><p>The array contains a list of execution_option objects, which are dictionaries with keys of field, value, and operator just like Evaluation Spec's filter objects. </p><p></p><p>Example : </p><pre><code>"execution_options": [
  {
    "field": "user_ids",
    "value": [
      "3305578009767732"
    ],
    "operator": "EQUAL"
  }
]
</code></pre></td></tr></tbody></table>

<table><thead><tr><th>Value for parameter `schedule_spec`</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>schedule_type</td><td>String</td><td>schedule_spec[schedule_type] must be one of the following values: DAILY, HOURLY, SEMI_HOURLY, CUSTOM"</td></tr><tr><td>schedule</td><td>Array</td><td><p>If schedule_type is CUSTOM, you must also specify the list of custom schedules, or times when the rule should run. In the schedule list, each individual specification can be composed of a combination of the following fields. The only requirement is that at least one of start_minute or days must exist in each entry.</p><p></p><p>Example </p><p>If schedule_type is CUSTOM</p><pre><code> "schedule": [
   {
      "start_minute": 0,
     "days": [2, 5]
   }
 ]
</code></pre></td></tr></tbody></table>

<mark style="color:green;">`POST`</mark> `https://us-central1-appgregator.cloudfunctions.net/facebook/adrules/`

#### Query Parameters

| Name                                               | Type   | Description           |
| -------------------------------------------------- | ------ | --------------------- |
| name<mark style="color:red;">\*</mark>             | String | ft-4                  |
| connection\_name<mark style="color:red;">\*</mark> | String | fbads-01              |
| adaccount\_id<mark style="color:red;">\*</mark>    | String | act\_1514519918873559 |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| x-api-key<mark style="color:red;">\*</mark> | String | U2Fsd...    |

{% tabs %}
{% tab title="201: Created Created" %}

```shell
{
    "id": "23852206730700549"
}
```

{% endtab %}
{% endtabs %}

<details>

<summary>Body JSON</summary>

```shell
{
  "name": "Rules-7",
  "status": "DISABLED",
  "evaluation_spec": {
    "evaluation_type": "SCHEDULE",
    "filters": [
      {
        "field": "lifetime_impressions",
        "value": "8000",
        "operator": "GREATER_THAN"
      },
      {
        "field": "cost_per",
        "value": "10",
        "operator": "GREATER_THAN"
      },
      {
        "field": "entity_type",
        "value": "CAMPAIGN",
        "operator": "EQUAL"
      },
      {
        "field": "time_preset",
        "value": "MAXIMUM",
        "operator": "EQUAL"
      }
    ]
  },
  "execution_spec": {
    "execution_type": "PAUSE",
    "execution_options": [
      {
        "field": "user_ids",
        "value": [
          "3305578009767732"
        ],
        "operator": "EQUAL"
      }
    ]
  },
  "schedule_spec": {
    "schedule_type": "DAILY"
  }
}
```

</details>

{% tabs %}
{% tab title="cURL" %}

```shell
curl --location --request POST 'https://us-central1-appgregator.cloudfunctions.net/facebook/adrules?name=ft-4&connection_name=fbads-01&adaccount_id=act_1514519918873559' \
--header 'x-api-key: U2Fsd...' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "Rules-7",
  "status": "DISABLED",
  "evaluation_spec": {
    "evaluation_type": "SCHEDULE",
    "filters": [
      {
        "field": "lifetime_impressions",
        "value": "8000",
        "operator": "GREATER_THAN"
      },
      {
        "field": "cost_per",
        "value": "10",
        "operator": "GREATER_THAN"
      },
      {
        "field": "entity_type",
        "value": "CAMPAIGN",
        "operator": "EQUAL"
      },
      {
        "field": "time_preset",
        "value": "MAXIMUM",
        "operator": "EQUAL"
      }
    ]
  },
  "execution_spec": {
    "execution_type": "PAUSE",
    "execution_options": [
      {
        "field": "user_ids",
        "value": [
          "3305578009767732"
        ],
        "operator": "EQUAL"
      }
    ]
  },
  "schedule_spec": {
    "schedule_type": "DAILY"
  }
}'
```

{% endtab %}

{% tab title="NodeJS - Axios" %}

```javascript
var axios = require('axios');
var data = JSON.stringify({
  "name": "Rules-7",
  "status": "DISABLED",
  "evaluation_spec": {
    "evaluation_type": "SCHEDULE",
    "filters": [
      {
        "field": "lifetime_impressions",
        "value": "8000",
        "operator": "GREATER_THAN"
      },
      {
        "field": "cost_per",
        "value": "10",
        "operator": "GREATER_THAN"
      },
      {
        "field": "entity_type",
        "value": "CAMPAIGN",
        "operator": "EQUAL"
      },
      {
        "field": "time_preset",
        "value": "MAXIMUM",
        "operator": "EQUAL"
      }
    ]
  },
  "execution_spec": {
    "execution_type": "PAUSE",
    "execution_options": [
      {
        "field": "user_ids",
        "value": [
          "3305578009767732"
        ],
        "operator": "EQUAL"
      }
    ]
  },
  "schedule_spec": {
    "schedule_type": "DAILY"
  }
});

var config = {
  method: 'post',
  url: 'https://us-central1-appgregator.cloudfunctions.net/facebook/adrules?name=ft-4&connection_name=fbads-01&adaccount_id=act_1514519918873559',
  headers: { 
    'x-api-key': 'U2Fsd...', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

{% endtab %}

{% tab title="PHP - cURL" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://us-central1-appgregator.cloudfunctions.net/facebook/adrules?name=ft-4&connection_name=fbads-01&adaccount_id=act_1514519918873559',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "name": "Rules-7",
  "status": "DISABLED",
  "evaluation_spec": {
    "evaluation_type": "SCHEDULE",
    "filters": [
      {
        "field": "lifetime_impressions",
        "value": "8000",
        "operator": "GREATER_THAN"
      },
      {
        "field": "cost_per",
        "value": "10",
        "operator": "GREATER_THAN"
      },
      {
        "field": "entity_type",
        "value": "CAMPAIGN",
        "operator": "EQUAL"
      },
      {
        "field": "time_preset",
        "value": "MAXIMUM",
        "operator": "EQUAL"
      }
    ]
  },
  "execution_spec": {
    "execution_type": "PAUSE",
    "execution_options": [
      {
        "field": "user_ids",
        "value": [
          "3305578009767732"
        ],
        "operator": "EQUAL"
      }
    ]
  },
  "schedule_spec": {
    "schedule_type": "DAILY"
  }
}',
  CURLOPT_HTTPHEADER => array(
    'x-api-key: U2Fsd...',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}
{% endtabs %}
