REST API v3: POST view rules

Method to add a rule to an existing selection. This is an HTTP POST call to the following URL:

https://api.copernica.com/v3/view/$id/rules?access_token=xxxx

The $id should be replaced by the ID of the view you want to add a rule to. After a successful call the ID of the created request is returned.

Available parameters

The following properties can be assigned to a rule in the message body. At least the name of the rule is required.

  • name: Name of the rule. This should be unique within the set of view rule names and is mandatory.
  • inverted: Boolean value that when set to "True" will return only profiles that do not adhere to the rule.
  • disabled: Boolean value that when set to "True" will disable the rule.

Conditions can be added with the method POST rule conditions.

JSON example

The following JSON demonstrates how to use the API method:

{
    "name": "rule-name",
    "inversed":false,
    "disabled":false
}

PHP Example

The following PHP script demonstrates how to call the API method:

// dependencies
require_once('copernica_rest_api.php');

// change this into your access token
$api = new CopernicaRestAPI("your-access-token", 3);

// data to pass to the call
$data = array(
   'name'       =>  'rule-name',
   'inverted'   =>  false,
   'disabled'   =>  false
);

// execute the call and store the result
$result = $api->post("view/{$viewID}/rules", $data);

If the call was succesful the result you stored above should contain the ID for the new rule. You can immediately use the ID to create new conditions using the POST rule conditions method. The example above requires the CopernicaRestApi class.

More information