REST API v2: GET rule
A method to request all metadata from a rule. This method does not support parameters. It is called by sending an HTTP GET request to the following URL:
https://api.copernica.com/v2/rule/$id?access_token=xxxx
In this, $id
needs to be replaced by the numerical identifier or the
name of the rule you wish to request the selections for.
Returned fields
This method returns rule data. The following properties are returned:
- ID: ID of the rule
- name: Name of the rule
- view: ID of the selection to which the rule belongs
- disabled: Boolean value whether the rule is disabled / not used to match profiles
- inverted: Boolean value whether this is an inverted rule, meaning that profiles are included in the rule if they do not match the rule
- conditions: Array of conditions in the rule
Conditions
A rule on its own contains conditions. For a profile to match a rule, it has to match all the conditions. The conditions property that is returned by this method holds an array of condition objects, with the following properties per condition:
- ID: numeric ID of the condition
- type: condition type
- rule: numeric ID of the rule to which the condition belongs
Based on the condition type, specific properties are set. Specific condition types are discussed in separate articles, which are linked in the "More information" section.
JSON example
The JSON for the rule might look something like this:
{
"ID":"4012",
"name":"Rule",
"view":"4184",
"conditions":{
"start":0,
"limit":100,
"count":1,
"data":[
{
"ID":"2110",
"type":"Field",
"rule":"4039",
"comparison":"equals",
"field":{
"ID":"22142",
"name":"subscribed",
"type":"text",
"value":"no",
"displayed":false,
"ordered":false,
"length":"255",
"textlines":"3",
"hidden":false,
"index":false
},
"value":"yes",
"other-field":false,
"numeric-comparison":false
}
],
"total":1
},
"inversed":false,
"disabled":false
}
PHP example
The following example demonstrates how to use this method:
// dependencies
require_once('copernica_rest_api.php');
// change this into your access token
$api = new CopernicaRestAPI("your-access-token", 2);
// do the call, and print result
print_r($api->get("rule/{$ruleID}"));
The example above requires the CopernicaRestApi class.
More information
- Overview of all API calls
- GET view rules
- POST view rule
- PUT rule
- DELETE rule
- PUT rule condition
- DELETE rule condition
Since there are many condition types which behave very differently each condition type is explained in a separate article below.