List

Retrieving a set of records through the RESTful API is simply a matter of sending an HTTP GET to the appropriate URL. Let us consider the example of retrieving the ping targets instrument for the purpose of integrating edge device monitoring with a central NMS. Using cURL to execute the following command:

curl https://rxg.dns/admin/scaffolds/ping_targets/index.json?api_key=P7Z...idA

The rXg responds with a JSON formatted dump of the current state of the ping targets. [{"name":"Google Public DNS 1","online":true, "target":"8.8.8.8","updated_at":"2012-06-13T17:11:04-04:00"}, {"name":"Google Public DNS 2","online":true, "target":"8.8.4.4","updated_at":"2012-04-23T12:10:11-04:00"}, {"name":"IDF Switch 2","online":true, "target":"192.168.117.20","updated_at":"2012-06-13T18:10:09-04:00"}, {"name":"VM NAT Net Router","online":false, "target":"192.168.117.254","updated_at":"2012-06-13T18:09:53-04:00"}, {"name":"Zone Director","online":false, "target":"172.30.80.10","updated_at":"2012-06-13T18:10:48-04:00"}] The suffix may be changed to retrieve the same information in XML format. ``` <?xml version="1.0" encoding="UTF-8"?> 3 2012-01-23T12:29:22-05:00 1 Google Public DNS 1 http://code.google.com/speed/public-dns/ true 8.8.8.8 2.0 2012-06-13T17:11:04-04:00 rxgd (PingMonitor) 3 2012-01-23T12:29:23-05:00 2 Google Public DNS 2

...

Filtering of the list is accomplished by passing CGI parameters to the RESTful API endpoint that match the fields of the model being retrieved. For example: curl https://rxg.dns/admin/scaffolds/ping_targets/index.json?api_key=P7Z...idA&name=Zone+Director' Results in the filtered response: [{"name":"Zone Director","online":false, "target":"172.30.80.10","updated_at":"2012-06-13T18:10:48-04:00"}] The same example formatted in XML: curl https://rxg.dns/admin/scaffolds/ping_targets/index.xml?api_key=P7Z...idA&name=Zone+Director' Results in the filtered response: <?xml version="1.0" encoding="UTF-8"?> 3 2012-06-13T18:09:36-04:00 admin 4 Zone Director false 172.30.80.10 3.0 2012-06-13T18:10:48-04:00 rxgd (PingMonitor) Filtering a retrieved list is commonly used to acquire the ID that needs to be passed during the create or update of a record. For example, if a **account** needs to be placed into a specific **account group** , the ID of the **account group** must be passed into the update request. It is highly recommended that external systems rely on names rather than IDs because the ID of records are automatically generated by the rXg and are not reliably replicated across a fleet. Therefore, most external systems must look up the ID of related objects before executing a create or update. Consider the following example Perl script: use LWP::Simple; use XML::Simple;

my $api_key = 'P7Z...idA'; my $groupname = 'Premium'; my $rxg = 'rxg.dns'; my $ctrl_action = 'admin/scaffolds/account_groups/index.xml';

$xml_raw = get("https://$rxg/$ctrl_action?api_key=$api_key;name=$groupname"); my $doc = XMLin($xml_raw); my $id_of_group = ${$doc}{'account-group'}{'id'}{'content'};

print "ID: $id_of_group\n"; ``` This script acquires the record ID of the account group named "Premium". The external system can reliably move a account object into the "Premium" account_group by running this script to acquire the appropriate record ID.


Cookies help us deliver our services. By using our services, you agree to our use of cookies.