Graph API Version

Ad Rule

Reading

A Rule that will be triggered based on certain criteria defined on ad objects, and perform custom actions.

Example

Graph API Explorer
GET /v4.0/{ad-rule-id} HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/{ad-rule-id}',
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
    "/{ad-rule-id}",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{ad-rule-id}",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{ad-rule-id}"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];
If you want to learn how to use the Graph API, read our Using Graph API guide.

Parameters

This endpoint doesn't have any parameters.

Fields

FieldDescription
id
numeric string

ID of the rule

account_id
numeric string

ID of the ad account that owns the rule

created_by

The user who created the rule

created_time
datetime

Time when the rule was created

evaluation_spec

Defines the evaluation spec upon which a rule will be executed

execution_spec

Defines the execution spec upon which a rule will be executed

name
string

The friendly name of a rule, optional for inline rules

schedule_spec

Specifies the schedule with which a rule will be evaluated

status
string

The status of a rule

updated_time
datetime

The time when the rule was last updated.

Edges

EdgeDescription

The execution history associated with this rule. Each entry represents a distinct run of the rule and provides any actions that may have been taken on any ad objects.

Validation Rules

ErrorDescription
100Invalid parameter

Creating

You can make a POST request to adrules_library edge from the following paths:
When posting to this edge, an AdRule will be created.

Parameters

ParameterDescription
account_id
numeric string

Ad Account ID. This is inferred from the path.

evaluation_spec
Object

Defines the evaluation spec upon which a rule will be executed

Required
evaluation_type
enum{SCHEDULE, TRIGGER}

Required
filters
list<Object>

Required
field
string

Required
value
numeric, string, boolean, list<>, or object-like arrays

Required
operator
enum{GREATER_THAN, LESS_THAN, EQUAL, NOT_EQUAL, IN_RANGE, NOT_IN_RANGE, IN, NOT_IN, CONTAIN, NOT_CONTAIN, ANY, ALL, NONE}

Required
trigger
Object

type
enum{METADATA_CREATION, METADATA_UPDATE, STATS_MILESTONE, STATS_CHANGE, DELIVERY_INSIGHTS_CHANGE}

Required
field
string

value
numeric, string, boolean, list<>, or object-like arrays

operator
enum{GREATER_THAN, LESS_THAN, EQUAL, NOT_EQUAL, IN_RANGE, NOT_IN_RANGE, IN, NOT_IN, CONTAIN, NOT_CONTAIN, ANY, ALL, NONE}

execution_spec
Object

Defines the execution spec upon which a rule will be executed

Required
execution_type
enum{PING_ENDPOINT, NOTIFICATION, PAUSE, REBALANCE_BUDGET, CHANGE_BUDGET, CHANGE_BID, ROTATE, UNPAUSE, CHANGE_CAMPAIGN_BUDGET}

Required
execution_options
list<Object>

field
string

Required
value
numeric, string, boolean, list<>, or object-like arrays

Required
operator
enum{EQUAL, IN}

Required
name
string

The friendly name of a rule, optional for inline rules

Required
schedule_spec
Object

Specifies the schedule with which a rule will be evaluated

schedule_type
enum{DAILY, HOURLY, SEMI_HOURLY, CUSTOM}

Required
schedule
list<Object>

start_minute
int64

end_minute
int64

days
list<int64>

status
enum {ENABLED, DISABLED, DELETED}

The status of a rule

Return Type

This endpoint supports read-after-write and will read the node represented by id in the return type.
Struct {
id: numeric string,
}

Validation Rules

ErrorDescription
200Permissions error
100Invalid parameter
2633This shared login is disabled. Go to Ads Manager for more information.
294Managing advertisements requires an access token with the extended permission for ads_management

Updating

You can update an AdRule by making a POST request to /{ad_rule_id}.

Parameters

ParameterDescription
evaluation_spec
Object

Defines the evaluation spec upon which a rule will be executed

evaluation_type
enum{SCHEDULE, TRIGGER}

Required
filters
list<Object>

Required
field
string

Required
value
numeric, string, boolean, list<>, or object-like arrays

Required
operator
enum{GREATER_THAN, LESS_THAN, EQUAL, NOT_EQUAL, IN_RANGE, NOT_IN_RANGE, IN, NOT_IN, CONTAIN, NOT_CONTAIN, ANY, ALL, NONE}

Required
trigger
Object

type
enum{METADATA_CREATION, METADATA_UPDATE, STATS_MILESTONE, STATS_CHANGE, DELIVERY_INSIGHTS_CHANGE}

Required
field
string

value
numeric, string, boolean, list<>, or object-like arrays

operator
enum{GREATER_THAN, LESS_THAN, EQUAL, NOT_EQUAL, IN_RANGE, NOT_IN_RANGE, IN, NOT_IN, CONTAIN, NOT_CONTAIN, ANY, ALL, NONE}

execution_spec
Object

Defines the execution spec upon which a rule will be executed

execution_type
enum{PING_ENDPOINT, NOTIFICATION, PAUSE, REBALANCE_BUDGET, CHANGE_BUDGET, CHANGE_BID, ROTATE, UNPAUSE, CHANGE_CAMPAIGN_BUDGET}

Required
execution_options
list<Object>

field
string

Required
value
numeric, string, boolean, list<>, or object-like arrays

Required
operator
enum{EQUAL, IN}

Required
name
string

The friendly name of a rule, optional for inline rules

schedule_spec
Object

Specifies the schedule with which a rule will be evaluated

schedule_type
enum{DAILY, HOURLY, SEMI_HOURLY, CUSTOM}

Required
schedule
list<Object>

start_minute
int64

end_minute
int64

days
list<int64>

status
enum {ENABLED, DISABLED, DELETED}

The status of a rule

Return Type

This endpoint supports read-after-write and will read the node to which you POSTed.
Struct {
success: bool,
}

Validation Rules

ErrorDescription
100Invalid parameter
200Permissions error

Deleting

You can delete an AdRule by making a DELETE request to /{ad_rule_id}.

Parameters

This endpoint doesn't have any parameters.

Return Type

Struct {
success: bool,
}

Validation Rules

ErrorDescription
200Permissions error
100Invalid parameter