6000122863 2015-09-03T12:25:10-04:00 6000191060 false Circonus API 2 2015-09-03T12:25:10-04:00 1 1 2015-09-03T12:39:36-04:00 1 1 At its foundation, Circonus is an API driven service. As a RESTful service, the Circonus API is designed to allow users to programmatically adjust monitors and alerts as their architecture evolves. The web portal "front-end" we provide to our customers is one interpretation of the Circonus API. Our customers can, and have, created their own "front-ends". The Circonus "back-end" can be accessed via the API to any system you wish - the data extracted from our "back-end" can be as simple as events, which are fed into an existing ticketing tool, or complex data extractions fed into a system like R. The “back-end”/”front-end” delineation is quite important here. In an API driven service like Circonus, the front-end is you or, more specifically, any thing you want to write against our APIs. Often times, when using services there are two types of API consumers: third-party tools and internal tools. On the internal tools side are the Python or Ruby or Java programs you write to turn knobs, register checks, configure alerts and otherwise poke and prod at your Circonus account. The third-party tools are simply the tools that someone else authored and released for your use. The full API Documentation is available here. <p> </p> <p>At its foundation, Circonus is an API driven service. As a RESTful service, the Circonus API is designed to allow users to programmatically adjust monitors and alerts as their architecture evolves.</p> <p><br></p> <p>The web portal "front-end" we provide to our customers is one interpretation of the Circonus API. Our customers can, and have, created their own "front-ends". The Circonus "back-end" can be accessed via the API to any system you wish - the data extracted from our "back-end" can be as simple as events, which are fed into an existing ticketing tool, or complex data extractions fed into a system like R.</p> <p><br></p> <p>The “back-end”/”front-end” delineation is quite important here. In an API driven service like Circonus, the front-end is you or, more specifically, any thing you want to write against our APIs. Often times, when using services there are two types of API consumers: third-party tools and internal tools. On the internal tools side are the Python or Ruby or Java programs you write to turn knobs, register checks, configure alerts and otherwise poke and prod at your Circonus account. The third-party tools are simply the tools that someone else authored and released for your use.</p> <p><br></p> <p><a href="http://login.circonus.com/resources/api" target="_blank" style="font-size: 13px;">The full API Documentation is available here</a>.</p> <p><br></p> <ul style="margin: 3px 0px 0px; padding: 0px; border: 0px; color: rgb(136, 137, 135);"></ul> 6000191060 267 6000055852 2015-09-03T12:39:36-04:00 1 2 1 1 The Circonus API 2015-09-03T12:39:36-04:00 6003235491 1 2015-09-03T12:53:12-04:00 1 1 These client examples are provided here as supplementary material for the appendix to our API Manual, where further instructions and a full explanation of the call details can be found. API Examples Using curl GET cid  1 2 3 curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ https://api.circonus.com/user/current  PUT cid  1 2 3 4 5 curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ -X PUT \ --data-binary '{"firstname":"Gonzo"}' \ https://api.circonus.com/user/current  DELETE cid  1 2 3 4 curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ -X DELETE \ https://api.circonus.com/graph/123456  POST type  1 2 3 4 5 curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ -X POST \ --data-binary '{"title":"Big Bird''s Birthday","description":"Big Bird is six (again)","start": 1332216000,"stop":1332302399}' \ https://api.circonus.com/annotation  GET type  1 2 3 curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ https://api.circonus.com/user   API Examples Using node.js GET cid    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #!/usr/bin/env node   // load the https module var https = require('https');   https.request({ host: 'api.circonus.com', path: '/user/current', headers: { 'X-Circonus-App-Name': 'ExampleApp', 'X-Circonus-Auth-Token': 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept': 'application/json' } }, function (response) {   // collect the body while we're getting chunks of it var body = ''; response.on('data', function (chunk) { body += chunk; });   // once we've got 'em all, handle them response.on('end', function () { // parse the JSON body result = JSON.parse(body);   // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { console.log( response.statusCode + ": "  + result.code + " (" + result.message + ")"); return; }   // result holds the data from the server console.log("Hello "+result.firstname+" "+result.lastname); }); }).end(); PUT cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 #!/usr/bin/env node   // load the https module var https = require('https');   var r = https.request({ host: 'api.circonus.com', path: '/user/current', headers: { 'X-Circonus-App-Name': 'ExampleApp', 'X-Circonus-Auth-Token': 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept': 'application/json' }, method: "PUT" }, function (response) {   // collect the body while we're getting chunks of it var body = ''; response.on('data', function (chunk) { body += chunk; });   // once we've got 'em all, handle them response.on('end', function () { // parse the JSON body result = JSON.parse(body);   // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { console.log( response.statusCode + ": "  + result.code + " (" + result.message + ")"); return; }   // print out the new name console.log("Your firstname is now " + result.firstname); }); });   // here's where we specify the updates for the user's firstname r.write(JSON.stringify({ 'firstname': "Gonzo" }));   r.end();   DELETE cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #!/usr/bin/env node   // load the https module var https = require('https');   https.request({ host: 'api.circonus.com', path: '/graph/123456', headers: { 'X-Circonus-App-Name': 'ExampleApp', 'X-Circonus-Auth-Token': 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept': 'application/json' }, method: "DELETE" }, function (response) {   // collect the body while we're getting chunks of it var body = ''; response.on('data', function (chunk) { body += chunk; });   // once we've got 'em all, handle them response.on('end', function () {   // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { result = JSON.parse(body); console.log( response.statusCode + ": "  + result.code + " (" + result.message + ")"); return; }   console.log("DELETED!"); }); }).end();   POST type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 #!/usr/bin/env node   // load the https module var https = require('https');   var r = https.request({ host: 'api.circonus.com', path: '/annotation', headers: { 'X-Circonus-App-Name': 'ExampleApp', 'X-Circonus-Auth-Token': 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept': 'application/json' }, method: "POST" }, function (response) {   // collect the body while we're getting chunks of it var body = ''; response.on('data', function (chunk) { body += chunk; });   // once we've got 'em all, handle them response.on('end', function () { // parse the JSON body result = JSON.parse(body);   // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { console.log( response.statusCode + ": "  + result.code + " (" + result.message + ")"); return; }   // print the new annotation details console.log("Created annotation: " + result['_cid'] + " (" + result.title + ")" ); }); });   // here's where we specify the values for the new object r.write(JSON.stringify({ 'title': "Big Bird's Birthday", 'description': "Big Bird is six (again)", 'start': 1332216000, 'stop': 1332302399 }));   r.end();   GET type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #!/usr/bin/env node   // load the https module var https = require('https');   https.request({ host: 'api.circonus.com', path: '/user', headers: { 'X-Circonus-App-Name': 'ExampleApp', 'X-Circonus-Auth-Token': 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept': 'application/json' } }, function (response) {   // collect the body while we're getting chunks of it var body = ''; response.on('data', function (chunk) { body += chunk; });   // once we've got 'em all, handle them response.on('end', function () { // parse the JSON body result = JSON.parse(body);   // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { console.log( response.statusCode + ": "  + result.code + " (" + result.message + ")"); return; }   // print out each user's details console.log("Users with access to the account:"); result.forEach(function(user) { console.log(" * " + user['_cid'] + " ("+user.firstname + " " + user.lastname + ")"); }); }); }).end();   API Examples Using PHP GET cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?php require_once 'HTTP/Request2.php';   $APP = "ExampleApp"; $TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66";   # talk to the server $request = new HTTP_Request2( "https://$APP:$TOKEN@api.circonus.com/user/current" ); $request->setHeader("Accept","application/json"); $response = $request->send();   # decode the JSON $result = json_decode($response->getBody());   # deal with exceptions by accessing the returned json and throwing why if (!preg_match("/^2/", $response->getStatus())) { throw new Exception( $response->getStatus().": ".$result->code." (".$result->message.")" ); }   # Hello World print "Hello ".$result->firstname." ".$result->lastname; ?>   PUT cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 <?php require_once 'HTTP/Request2.php';   $APP = "ExampleApp"; $TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66";   # talk to the server $request = new HTTP_Request2( "https://$APP:$TOKEN@api.circonus.com/user/current", HTTP_Request2::METHOD_PUT ); $request->setHeader("Accept","application/json"); $request->setBody(json_encode(array( "firstname" => "Gonzo", ))); $response = $request->send();   # decode the JSON $result = json_decode($response->getBody());   # deal with exceptions by accessing the returned json and throwing why if (!preg_match("/^2/", $response->getStatus())) { throw new Exception( $response->getStatus().": ".$result->code." (".$result->message.")" ); }   # And access the updated result returned from the server print "Your first name is now ".$result->firstname."\n"; ?>   DELETE cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <?php require_once 'HTTP/Request2.php';   $APP = "ExampleApp"; $TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66";   # talk to the server $request = new HTTP_Request2( "https://$APP:$TOKEN@api.circonus.com/graph/123456", HTTP_Request2::METHOD_DELETE ); $request->setHeader("Accept","application/json"); $response = $request->send();   # decode the JSON $result = json_decode($response->getBody());   # deal with exceptions by accessing the returned json and throwing why if (!preg_match("/^2/", $response->getStatus())) { throw new Exception( $response->getStatus().": ".$result->code." (".$result->message.")" ); }   # Hello World print "DELETED!\n"; ?>   POST type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <?php require_once 'HTTP/Request2.php';   $APP = "ExampleApp"; $TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66";   # talk to the server $request = new HTTP_Request2( "https://$APP:$TOKEN@api.circonus.com/annotation", HTTP_Request2::METHOD_POST ); $request->setHeader("Accept","application/json"); $request->setBody(json_encode(array( "title" => "Big Bird's Birthday", "description" => "Big Bird is six (again)", "start" => 1332216000, "stop" => 1332302399, ))); $response = $request->send();   # decode the JSON $result = json_decode($response->getBody());   # deal with exceptions by accessing the returned json and throwing why if (!preg_match("/^2/", $response->getStatus())) { throw new Exception( $response->getStatus().": ".$result->code." (".$result->message.")" ); }   # print out the new cid (and other details) print "Created annotation: ".$result->_cid." (".$result->title.")\n"; ?>   GET type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <?php require_once 'HTTP/Request2.php';   $APP = "ExampleApp"; $TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66";   # talk to the server $request = new HTTP_Request2( "https://$APP:$TOKEN@api.circonus.com/user" ); $request->setHeader("Accept","application/json"); $response = $request->send();   # decode the JSON $result = json_decode($response->getBody());   # deal with exceptions by accessing the returned json and throwing why if (!preg_match("/^2/", $response->getStatus())) { throw new Exception( $response->getStatus().": ".$result->code." (".$result->message.")" ); }   # print out each user's details print "Users with access to the account:\n"; foreach ($result as $user) { print " * ".$user->_cid." (".$user->firstname." ".$user->lastname.")\n"; } ?>   API Examples Using Perl GET cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #!/usr/bin/env perl   use strict; use warnings;   # these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny; use JSON::PP qw(decode_json);   # create an agent my $agent = HTTP::Tiny->new( default_headers => { 'X-Circonus-App-Name' => 'ExampleApp', 'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept' => "application/json", }, );   # talk to the API over HTTP my $response = $agent->get('https://api.circonus.com/user/current');   # parse the result as JSON my $result = $response->{content} ? decode_json $response->{content} : {};   # handle errors unless ($response->{success}) { die "$response->{status}: $result->{code} ($result->{message})\n"; }   # result holds the data from the server result print "Hello $result->{firstname} $result->{lastname}\n";   PUT cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 #!/usr/bin/env perl   use strict; use warnings;   # these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny; use JSON::PP qw(encode_json decode_json);   # create an agent my $agent = HTTP::Tiny->new( default_headers => { 'X-Circonus-App-Name' => 'ExampleApp', 'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept' => "application/json", }, );   # talk to the API over HTTP my $response = $agent->put('https://api.circonus.com/user/current', { content => encode_json { firstname => "Gonzo", }, });   # parse the result as JSON my $result = $response->{content} ? decode_json $response->{content} : {};   # handle errors unless ($response->{success}) { die "$response->{status}: $result->{code} ($result->{message})\n"; }   print "Your first name is now $result->{firstname}\n";   DELETE cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #!/usr/bin/env perl   use strict; use warnings;   # these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny; use JSON::PP qw(decode_json);   # create an agent my $agent = HTTP::Tiny->new( default_headers => { 'X-Circonus-App-Name' => 'ExampleApp', 'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept' => "application/json", }, );   # talk to the API over HTTP my $response = $agent->delete('https://api.circonus.com/graph/123456');   # parse the result as JSON my $result = $response->{content} ? decode_json $response->{content} : {};   # handle errors unless ($response->{success}) { die "$response->{status}: $result->{code} ($result->{message})\n"; }   print "DELETED!\n";   POST type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 #!/usr/bin/env perl   use strict; use warnings;   # these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny; use JSON::PP qw(encode_json decode_json);   # create an agent my $agent = HTTP::Tiny->new( default_headers => { 'X-Circonus-App-Name' => 'ExampleApp', 'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept' => "application/json", }, );   # talk to the API over HTTP my $response = $agent->post('https://api.circonus.com/annotation', { content => encode_json { title => "Big Bird's Birthday", description => "Big Bird is six (again)", start => 1332216000, stop => 1332302399, } });   # parse the result as JSON my $result = $response->{content} ? decode_json $response->{content} : {};   # handle errors unless ($response->{success}) { die "$response->{status}: $result->{code} ($result->{message})\n"; }   # print out the new cid (and other details) print "Created annotation: $result->{_cid} ($result->{title})\n";   GET type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 #!/usr/bin/env perl   use strict; use warnings;   # these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny; use JSON::PP qw(decode_json);   # create an agent my $agent = HTTP::Tiny->new( default_headers => { 'X-Circonus-App-Name' => 'ExampleApp', 'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66', 'Accept' => "application/json", }, );   # talk to the API over HTTP my $response = $agent->get('https://api.circonus.com/user');   # parse the result as JSON my $result = $response->{content} ? decode_json $response->{content} : {};   # handle errors unless ($response->{success}) { die "$response->{status}: $result->{code} ($result->{message})\n"; }   # print out each user's details print "Users with access to the account:\n"; foreach my $user (@{ $result }) { print " * $user->{_cid} ($user->{firstname} $user->{lastname})\n"; }   API Examples Using Python GET cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import requests;   try: response = requests.get( "https://api.circonus.com/user/current", auth=("ExampleApp","fb349ef1-91e4-4b05-aaa2-52246b77ea66"), headers={'Accept': "application/json"} ); response.raise_for_status()   print "Hello %s %s" % ( response.json['firstname'], response.json['lastname'] )   # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e: print "%s: %s (%s)" % ( e.response.status_code, e.response.json['code'], e.response.json['message'] )   PUT cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import requests; import json;   try: response = requests.put( "https://api.circonus.com/user/current", json.dumps({ 'firstname': 'Gonzo' }), auth=("ExampleApp","fb349ef1-91e4-4b05-aaa2-52246b77ea66"), headers={'Accept': "application/json"} ) response.raise_for_status()   print "Your first name is now %s" % response.json['firstname']   # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e: print "%s: %s (%s)" % ( e.response.status_code, e.response.json['code'], e.response.json['message'] )   DELETE cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import requests;   try: response = requests.delete( "https://api.circonus.com/graph/123456", auth=("ExampleApp","fb349ef1-91e4-4b05-aaa2-52246b77ea66"), headers={'Accept': "application/json"} ) response.raise_for_status()   print "DELETED!"   # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e: print "%s: %s (%s)" % ( e.response.status_code, e.response.json['code'], e.response.json['message'] )   POST type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 import requests; import json;   try: response = requests.post( "https://api.circonus.com/annotation", json.dumps({ "title": "Big Bird's Birthday", "description": "Big Bird is six (again)", "start": 1332216000, "stop": 1332302399 }), auth=("ExampleApp","fb349ef1-91e4-4b05-aaa2-52246b77ea66"), headers={'Accept': "application/json"} ) response.raise_for_status()   print "Created annotation: %s (%s)" % ( response.json["_cid"], response.json["title"] )   # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e: print "%s: %s (%s)" % ( e.response.status_code, e.response.json['code'], e.response.json['message'] )   GET type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 import requests;   try: response = requests.get( "https://api.circonus.com/user", auth=("ExampleApp","fb349ef1-91e4-4b05-aaa2-52246b77ea66"), headers={'Accept': "application/json"} ); response.raise_for_status()   # print out each user's details print "Users with access to the account:" for user in response.json: print " * %s (%s %s)" % ( user['email'], user['firstname'], user['lastname'], )   # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e: print "%s: %s (%s)" % ( e.response.status_code, e.response.json['code'], e.response.json['message'] )   API Examples Using Ruby GET cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #!/usr/bin/ruby   require 'rubygems' require 'json' require 'rest_client'   # setup client circonus = RestClient::Resource.new("https://api.circonus.com", :headers => { :x_circonus_app_name => "ExampleApp", :x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66", :accept => 'application/json', })   begin # get and parse response = circonus["/user/current"].get; result = JSON.parse(response);   # print out the result puts "Hello #{result['firstname']} #{result['lastname']}";   rescue RestClient::Exception => ex # deal with exceptions by accessing the returned json and printing out why result = JSON.parse(ex.http_body) puts "#{ex.http_code}: #{result['code']} (#{result['message']})" end   PUT cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #!/usr/bin/ruby   require 'rubygems' require 'json' require 'rest_client'   # setup client circonus = RestClient::Resource.new("https://api.circonus.com", :headers => { :x_circonus_app_name => "ExampleApp", :x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66", :accept => 'application/json', })   begin # put and parse the updated object response = circonus["/user/current"].put( { :firstname => "Gonzo" }.to_json() ); result = JSON.parse(response);   puts "Your first name is now #{result['firstname']}";   rescue RestClient::Exception => ex # deal with exceptions by accessing the returned json and printing out why result = JSON.parse(ex.http_body) puts "#{ex.http_code}: #{result['code']} (#{result['message']})" end   DELETE cid   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #!/usr/bin/ruby   require 'rubygems' require 'json' require 'rest_client'   # setup client circonus = RestClient::Resource.new("https://api.circonus.com", :headers => { :x_circonus_app_name => "ExampleApp", :x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66", :accept => 'application/json', })   begin # delete response = circonus["/graph/123456"].delete;   puts "DELETED!"   rescue RestClient::Exception => ex # deal with exceptions by accessing the returned json and printing out why result = JSON.parse(ex.http_body) puts "#{ex.http_code}: #{result['code']} (#{result['message']})" end   POST type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #!/usr/bin/ruby   require 'rubygems' require 'json' require 'rest_client'   # setup client circonus = RestClient::Resource.new("https://api.circonus.com", :headers => { :x_circonus_app_name => "ExampleApp", :x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66", :accept => 'application/json', })   begin # put and parse the updated object response = circonus["/annotation"].post( { :title => "Big Bird's Birthday", :description => "Big Bird is six (again)", :start => 1332216000, :stop => 1332302399, }.to_json() ); result = JSON.parse(response);   puts "Created annotation: #{result['_cid']} (#{result['title']})";   rescue RestClient::Exception => ex # deal with exceptions by accessing the returned json and printing out why result = JSON.parse(ex.http_body) puts "#{ex.http_code}: #{result['code']} (#{result['message']})" end   GET type   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #!/usr/bin/ruby   require 'rubygems' require 'json' require 'rest_client'   # setup client circonus = RestClient::Resource.new("https://api.circonus.com", :headers => { :x_circonus_app_name => "ExampleApp", :x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66", :accept => 'application/json', })   begin # get and parse response = circonus["/user"].get; result = JSON.parse(response);   # print out each user's details puts "Users with access to the account:"; result.each { |user| puts " * #{user['_cid']} (#{user['firstname']} #{user['lastname']})\n"; }   rescue RestClient::Exception => ex # deal with exceptions by accessing the returned json and printing out why result = JSON.parse(ex.http_body) puts "#{ex.http_code}: #{result['code']} (#{result['message']})" end   <p>These client examples are provided here as supplementary material for the appendix to our <a href="https://login.circonus.com/resources/api" rel="noreferrer">API Manual</a>, where further instructions and a full explanation of the call details can be found.</p><p><br></p><h1>API Examples Using curl</h1><h4><br></h4><h4>GET cid<span style="line-height: 1.3;"> </span> </h4><div><div class="syntaxhighlighter text" id="highlighter_500666"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="text plain">curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \</code></div> <div class="line number2 index1 alt1 current"><code class="text plain">-H "Accept: application/json" \<img id="cursor" rel="cursor" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" style="width: 0px; height: 0px;" class="fr-dii fr-draggable"></code></div> <div class="line number3 index2 alt2"><code class="text plain"><a href="https://api.circonus.com/user/current">https://api.circonus.com/user/current</a></code></div> </div></td> </tr></tbody></table></div></div></div><h4> <span style="line-height: 1.3;"> </span>PUT cid<span style="line-height: 1.3;"> </span> </h4><div><div class="syntaxhighlighter text" id="highlighter_837569"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="text plain">curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \</code></div> <div class="line number2 index1 alt1"><code class="text plain">-H "Accept: application/json" \</code></div> <div class="line number3 index2 alt2"><code class="text plain">-X PUT \</code></div> <div class="line number4 index3 alt1"><code class="text plain">--data-binary '{"firstname":"Gonzo"}' \</code></div> <div class="line number5 index4 alt2"><code class="text plain"><a href="https://api.circonus.com/user/current">https://api.circonus.com/user/current</a></code></div> </div></td> </tr></tbody></table></div></div></div><h4> <span style="line-height: 1.3;"> </span>DELETE cid<span style="line-height: 1.3;"> </span> </h4><div><div class="syntaxhighlighter text" id="highlighter_253146"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="text plain">curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \</code></div> <div class="line number2 index1 alt1"><code class="text plain">-H "Accept: application/json" \</code></div> <div class="line number3 index2 alt2"><code class="text plain">-X DELETE \</code></div> <div class="line number4 index3 alt1"><code class="text plain"><a href="https://api.circonus.com/graph/123456">https://api.circonus.com/graph/123456</a></code></div> </div></td> </tr></tbody></table></div></div></div><h4> <span style="line-height: 1.3;"> </span>POST type<span style="line-height: 1.3;"> </span> </h4><div><div class="syntaxhighlighter text" id="highlighter_404323"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="text plain">curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \</code></div> <div class="line number2 index1 alt1"><code class="text plain">-H "Accept: application/json" \</code></div> <div class="line number3 index2 alt2"><code class="text plain">-X POST \</code></div> <div class="line number4 index3 alt1"><code class="text plain">--data-binary '{"title":"Big Bird''s Birthday","description":"Big Bird is six (again)","start": 1332216000,"stop":1332302399}' \</code></div> <div class="line number5 index4 alt2"><code class="text plain"><a href="https://api.circonus.com/annotation">https://api.circonus.com/annotation</a></code></div> </div></td> </tr></tbody></table></div></div></div><h4> <span style="line-height: 1.3;"> </span>GET type<span style="line-height: 1.3;"> </span> </h4><div><div class="syntaxhighlighter text" id="highlighter_817428"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="text plain">curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \</code></div> <div class="line number2 index1 alt1"><code class="text plain">-H "Accept: application/json" \</code></div> <div class="line number3 index2 alt2"><code class="text plain"><a href="https://api.circonus.com/user">https://api.circonus.com/user</a></code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><h1>API Examples Using node.js</h1><h3><br></h3><h3>GET cid</h3><p> <span> </span></p><div><div class="syntaxhighlighter js" id="highlighter_73576"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> <div class="line number35 index34 alt2">35</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="js preprocessor">#!/usr/bin/env node</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"><code class="js comments">// load the https module</code></div> <div class="line number4 index3 alt1"> <code class="js keyword">var</code> <code class="js plain">https = require(</code><code class="js string">'https'</code><code class="js plain">);</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="js plain">https.request({</code></div> <div class="line number7 index6 alt2"> <code class="js plain">host: </code><code class="js string">'api.circonus.com'</code><code class="js plain">,</code> </div> <div class="line number8 index7 alt1"> <code class="js plain">path: </code><code class="js string">'/user/current'</code><code class="js plain">,</code> </div> <div class="line number9 index8 alt2"><code class="js plain">headers: {</code></div> <div class="line number10 index9 alt1"> <code class="js string">'X-Circonus-App-Name'</code><code class="js plain">: </code><code class="js string">'ExampleApp'</code><code class="js plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="js string">'X-Circonus-Auth-Token'</code><code class="js plain">: </code><code class="js string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="js plain">,</code> </div> <div class="line number12 index11 alt1"> <code class="js string">'Accept'</code><code class="js plain">: </code><code class="js string">'application/json'</code> </div> <div class="line number13 index12 alt2"><code class="js plain">}</code></div> <div class="line number14 index13 alt1"> <code class="js plain">}, </code><code class="js keyword">function</code> <code class="js plain">(response) {</code> </div> <div class="line number15 index14 alt2"> </div> <div class="line number16 index15 alt1"><code class="js comments">// collect the body while we're getting chunks of it</code></div> <div class="line number17 index16 alt2"> <code class="js keyword">var</code> <code class="js plain">body = '</code><code class="js string">';</code> </div> <div class="line number18 index17 alt1"> <code class="js string">response.on('</code><code class="js plain">data</code><code class="js string">', function (chunk) { body += chunk; });</code> </div> <div class="line number19 index18 alt2"> </div> <div class="line number20 index19 alt1"> <code class="js string">// once we'</code><code class="js plain">ve got </code><code class="js string">'em all, handle them</code> </div> <div class="line number21 index20 alt2"> <code class="js string">response.on('</code><code class="js plain">end', </code><code class="js keyword">function</code> <code class="js plain">() {</code> </div> <div class="line number22 index21 alt1"><code class="js comments">// parse the JSON body</code></div> <div class="line number23 index22 alt2"><code class="js plain">result = JSON.parse(body);</code></div> <div class="line number24 index23 alt1"> </div> <div class="line number25 index24 alt2"><code class="js comments">// handle errors by extracting the code/message from the response</code></div> <div class="line number26 index25 alt1"> <code class="js keyword">if</code> <code class="js plain">(response.statusCode &lt; 200 || response.statusCode &gt;= 300) {</code> </div> <div class="line number27 index26 alt2"> <code class="js plain">console.log( response.statusCode + </code><code class="js string">": "</code> </div> <div class="line number28 index27 alt1"> <code class="js plain">+ result.code + </code><code class="js string">" ("</code> <code class="js plain">+ result.message + </code><code class="js string">")"</code><code class="js plain">);</code> </div> <div class="line number29 index28 alt2"> <code class="js keyword">return</code><code class="js plain">;</code> </div> <div class="line number30 index29 alt1"><code class="js plain">}</code></div> <div class="line number31 index30 alt2"> </div> <div class="line number32 index31 alt1"><code class="js comments">// result holds the data from the server</code></div> <div class="line number33 index32 alt2"> <code class="js plain">console.log(</code><code class="js string">"Hello "</code><code class="js plain">+result.firstname+</code><code class="js string">" "</code><code class="js plain">+result.lastname);</code> </div> <div class="line number34 index33 alt1"><code class="js plain">});</code></div> <div class="line number35 index34 alt2"><code class="js plain">}).end();</code></div> </div></td> </tr></tbody></table></div></div></div><p><br></p><p>PUT cid</p><p> </p><div><div class="syntaxhighlighter js" id="highlighter_558972"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> <div class="line number35 index34 alt2">35</div> <div class="line number36 index35 alt1">36</div> <div class="line number37 index36 alt2">37</div> <div class="line number38 index37 alt1">38</div> <div class="line number39 index38 alt2">39</div> <div class="line number40 index39 alt1">40</div> <div class="line number41 index40 alt2">41</div> <div class="line number42 index41 alt1">42</div> <div class="line number43 index42 alt2">43</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="js preprocessor">#!/usr/bin/env node</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"><code class="js comments">// load the https module</code></div> <div class="line number4 index3 alt1"> <code class="js keyword">var</code> <code class="js plain">https = require(</code><code class="js string">'https'</code><code class="js plain">);</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"> <code class="js keyword">var</code> <code class="js plain">r = https.request({</code> </div> <div class="line number7 index6 alt2"> <code class="js plain">host: </code><code class="js string">'api.circonus.com'</code><code class="js plain">,</code> </div> <div class="line number8 index7 alt1"> <code class="js plain">path: </code><code class="js string">'/user/current'</code><code class="js plain">,</code> </div> <div class="line number9 index8 alt2"><code class="js plain">headers: {</code></div> <div class="line number10 index9 alt1"> <code class="js string">'X-Circonus-App-Name'</code><code class="js plain">: </code><code class="js string">'ExampleApp'</code><code class="js plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="js string">'X-Circonus-Auth-Token'</code><code class="js plain">: </code><code class="js string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="js plain">,</code> </div> <div class="line number12 index11 alt1"> <code class="js string">'Accept'</code><code class="js plain">: </code><code class="js string">'application/json'</code> </div> <div class="line number13 index12 alt2"><code class="js plain">},</code></div> <div class="line number14 index13 alt1"> <code class="js plain">method: </code><code class="js string">"PUT"</code> </div> <div class="line number15 index14 alt2"> <code class="js plain">}, </code><code class="js keyword">function</code> <code class="js plain">(response) {</code> </div> <div class="line number16 index15 alt1"> </div> <div class="line number17 index16 alt2"><code class="js comments">// collect the body while we're getting chunks of it</code></div> <div class="line number18 index17 alt1"> <code class="js keyword">var</code> <code class="js plain">body = '</code><code class="js string">';</code> </div> <div class="line number19 index18 alt2"> <code class="js string">response.on('</code><code class="js plain">data</code><code class="js string">', function (chunk) { body += chunk; });</code> </div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"> <code class="js string">// once we'</code><code class="js plain">ve got </code><code class="js string">'em all, handle them</code> </div> <div class="line number22 index21 alt1"> <code class="js string">response.on('</code><code class="js plain">end</code><code class="js string">', function () {</code> </div> <div class="line number23 index22 alt2"><code class="js string">// parse the JSON body</code></div> <div class="line number24 index23 alt1"><code class="js string">result = JSON.parse(body);</code></div> <div class="line number25 index24 alt2"> </div> <div class="line number26 index25 alt1"><code class="js string">// handle errors by extracting the code/message from the response</code></div> <div class="line number27 index26 alt2"><code class="js string">if (response.statusCode &lt; 200 || response.statusCode &gt;= 300) {</code></div> <div class="line number28 index27 alt1"><code class="js string">console.log( response.statusCode + ": " </code></div> <div class="line number29 index28 alt2"><code class="js string">+ result.code + " (" + result.message + ")");</code></div> <div class="line number30 index29 alt1"><code class="js string">return;</code></div> <div class="line number31 index30 alt2"><code class="js string">}</code></div> <div class="line number32 index31 alt1"> </div> <div class="line number33 index32 alt2"><code class="js string">// print out the new name</code></div> <div class="line number34 index33 alt1"><code class="js string">console.log("Your firstname is now " + result.firstname);</code></div> <div class="line number35 index34 alt2"><code class="js string">});</code></div> <div class="line number36 index35 alt1"><code class="js string">});</code></div> <div class="line number37 index36 alt2"> </div> <div class="line number38 index37 alt1"> <code class="js string">// here'</code><code class="js plain">s where we specify the updates </code><code class="js keyword">for</code> <code class="js plain">the user</code><code class="js string">'s firstname</code> </div> <div class="line number39 index38 alt2"><code class="js string">r.write(JSON.stringify({</code></div> <div class="line number40 index39 alt1"> <code class="js string">'</code><code class="js plain">firstname': </code><code class="js string">"Gonzo"</code> </div> <div class="line number41 index40 alt2"><code class="js plain">}));</code></div> <div class="line number42 index41 alt1"> </div> <div class="line number43 index42 alt2"><code class="js plain">r.end();</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>DELETE cid</p><p> </p><div><div class="syntaxhighlighter js" id="highlighter_68334"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="js preprocessor">#!/usr/bin/env node</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"><code class="js comments">// load the https module</code></div> <div class="line number4 index3 alt1"> <code class="js keyword">var</code> <code class="js plain">https = require(</code><code class="js string">'https'</code><code class="js plain">);</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="js plain">https.request({</code></div> <div class="line number7 index6 alt2"> <code class="js plain">host: </code><code class="js string">'api.circonus.com'</code><code class="js plain">,</code> </div> <div class="line number8 index7 alt1"> <code class="js plain">path: </code><code class="js string">'/graph/123456'</code><code class="js plain">,</code> </div> <div class="line number9 index8 alt2"><code class="js plain">headers: {</code></div> <div class="line number10 index9 alt1"> <code class="js string">'X-Circonus-App-Name'</code><code class="js plain">: </code><code class="js string">'ExampleApp'</code><code class="js plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="js string">'X-Circonus-Auth-Token'</code><code class="js plain">: </code><code class="js string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="js plain">,</code> </div> <div class="line number12 index11 alt1"> <code class="js string">'Accept'</code><code class="js plain">: </code><code class="js string">'application/json'</code> </div> <div class="line number13 index12 alt2"><code class="js plain">},</code></div> <div class="line number14 index13 alt1"> <code class="js plain">method: </code><code class="js string">"DELETE"</code> </div> <div class="line number15 index14 alt2"> <code class="js plain">}, </code><code class="js keyword">function</code> <code class="js plain">(response) {</code> </div> <div class="line number16 index15 alt1"> </div> <div class="line number17 index16 alt2"><code class="js comments">// collect the body while we're getting chunks of it</code></div> <div class="line number18 index17 alt1"> <code class="js keyword">var</code> <code class="js plain">body = '</code><code class="js string">';</code> </div> <div class="line number19 index18 alt2"> <code class="js string">response.on('</code><code class="js plain">data</code><code class="js string">', function (chunk) { body += chunk; });</code> </div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"> <code class="js string">// once we'</code><code class="js plain">ve got </code><code class="js string">'em all, handle them</code> </div> <div class="line number22 index21 alt1"> <code class="js string">response.on('</code><code class="js plain">end', </code><code class="js keyword">function</code> <code class="js plain">() {</code> </div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1"><code class="js comments">// handle errors by extracting the code/message from the response</code></div> <div class="line number25 index24 alt2"> <code class="js keyword">if</code> <code class="js plain">(response.statusCode &lt; 200 || response.statusCode &gt;= 300) {</code> </div> <div class="line number26 index25 alt1"><code class="js plain">result = JSON.parse(body);</code></div> <div class="line number27 index26 alt2"> <code class="js plain">console.log( response.statusCode + </code><code class="js string">": "</code> </div> <div class="line number28 index27 alt1"> <code class="js plain">+ result.code + </code><code class="js string">" ("</code> <code class="js plain">+ result.message + </code><code class="js string">")"</code><code class="js plain">);</code> </div> <div class="line number29 index28 alt2"> <code class="js keyword">return</code><code class="js plain">;</code> </div> <div class="line number30 index29 alt1"><code class="js plain">}</code></div> <div class="line number31 index30 alt2"> </div> <div class="line number32 index31 alt1"> <code class="js plain">console.log(</code><code class="js string">"DELETED!"</code><code class="js plain">);</code> </div> <div class="line number33 index32 alt2"><code class="js plain">});</code></div> <div class="line number34 index33 alt1"><code class="js plain">}).end();</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>POST type</p><p> </p><div><div class="syntaxhighlighter js" id="highlighter_123089"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> <div class="line number35 index34 alt2">35</div> <div class="line number36 index35 alt1">36</div> <div class="line number37 index36 alt2">37</div> <div class="line number38 index37 alt1">38</div> <div class="line number39 index38 alt2">39</div> <div class="line number40 index39 alt1">40</div> <div class="line number41 index40 alt2">41</div> <div class="line number42 index41 alt1">42</div> <div class="line number43 index42 alt2">43</div> <div class="line number44 index43 alt1">44</div> <div class="line number45 index44 alt2">45</div> <div class="line number46 index45 alt1">46</div> <div class="line number47 index46 alt2">47</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="js preprocessor">#!/usr/bin/env node</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"><code class="js comments">// load the https module</code></div> <div class="line number4 index3 alt1"> <code class="js keyword">var</code> <code class="js plain">https = require(</code><code class="js string">'https'</code><code class="js plain">);</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"> <code class="js keyword">var</code> <code class="js plain">r = https.request({</code> </div> <div class="line number7 index6 alt2"> <code class="js plain">host: </code><code class="js string">'api.circonus.com'</code><code class="js plain">,</code> </div> <div class="line number8 index7 alt1"> <code class="js plain">path: </code><code class="js string">'/annotation'</code><code class="js plain">,</code> </div> <div class="line number9 index8 alt2"><code class="js plain">headers: {</code></div> <div class="line number10 index9 alt1"> <code class="js string">'X-Circonus-App-Name'</code><code class="js plain">: </code><code class="js string">'ExampleApp'</code><code class="js plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="js string">'X-Circonus-Auth-Token'</code><code class="js plain">: </code><code class="js string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="js plain">,</code> </div> <div class="line number12 index11 alt1"> <code class="js string">'Accept'</code><code class="js plain">: </code><code class="js string">'application/json'</code> </div> <div class="line number13 index12 alt2"><code class="js plain">},</code></div> <div class="line number14 index13 alt1"> <code class="js plain">method: </code><code class="js string">"POST"</code> </div> <div class="line number15 index14 alt2"> <code class="js plain">}, </code><code class="js keyword">function</code> <code class="js plain">(response) {</code> </div> <div class="line number16 index15 alt1"> </div> <div class="line number17 index16 alt2"><code class="js comments">// collect the body while we're getting chunks of it</code></div> <div class="line number18 index17 alt1"> <code class="js keyword">var</code> <code class="js plain">body = '</code><code class="js string">';</code> </div> <div class="line number19 index18 alt2"> <code class="js string">response.on('</code><code class="js plain">data</code><code class="js string">', function (chunk) { body += chunk; });</code> </div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"> <code class="js string">// once we'</code><code class="js plain">ve got </code><code class="js string">'em all, handle them</code> </div> <div class="line number22 index21 alt1"> <code class="js string">response.on('</code><code class="js plain">end</code><code class="js string">', function () {</code> </div> <div class="line number23 index22 alt2"><code class="js string">// parse the JSON body</code></div> <div class="line number24 index23 alt1"><code class="js string">result = JSON.parse(body);</code></div> <div class="line number25 index24 alt2"> </div> <div class="line number26 index25 alt1"><code class="js string">// handle errors by extracting the code/message from the response</code></div> <div class="line number27 index26 alt2"><code class="js string">if (response.statusCode &lt; 200 || response.statusCode &gt;= 300) {</code></div> <div class="line number28 index27 alt1"><code class="js string">console.log( response.statusCode + ": " </code></div> <div class="line number29 index28 alt2"><code class="js string">+ result.code + " (" + result.message + ")");</code></div> <div class="line number30 index29 alt1"><code class="js string">return;</code></div> <div class="line number31 index30 alt2"><code class="js string">}</code></div> <div class="line number32 index31 alt1"> </div> <div class="line number33 index32 alt2"><code class="js string">// print the new annotation details</code></div> <div class="line number34 index33 alt1"> <code class="js string">console.log("Created annotation: " + result['</code><code class="js plain">_cid</code><code class="js string">'] +</code> </div> <div class="line number35 index34 alt2"><code class="js string">" (" + result.title + ")" );</code></div> <div class="line number36 index35 alt1"><code class="js string">});</code></div> <div class="line number37 index36 alt2"><code class="js string">});</code></div> <div class="line number38 index37 alt1"> </div> <div class="line number39 index38 alt2"> <code class="js string">// here'</code><code class="js plain">s where we specify the values </code><code class="js keyword">for</code> <code class="js plain">the </code><code class="js keyword">new</code> <code class="js plain">object</code> </div> <div class="line number40 index39 alt1"><code class="js plain">r.write(JSON.stringify({</code></div> <div class="line number41 index40 alt2"> <code class="js string">'title'</code><code class="js plain">: </code><code class="js string">"Big Bird's Birthday"</code><code class="js plain">,</code> </div> <div class="line number42 index41 alt1"> <code class="js plain">'description</code><code class="js string">': "Big Bird is six (again)",</code> </div> <div class="line number43 index42 alt2"> <code class="js string">'</code><code class="js plain">start</code><code class="js string">': 1332216000,</code> </div> <div class="line number44 index43 alt1"> <code class="js string">'</code><code class="js plain">stop': 1332302399</code> </div> <div class="line number45 index44 alt2"><code class="js plain">}));</code></div> <div class="line number46 index45 alt1"> </div> <div class="line number47 index46 alt2"><code class="js plain">r.end();</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>GET type</p><p> </p><div><div class="syntaxhighlighter js" id="highlighter_104190"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> <div class="line number35 index34 alt2">35</div> <div class="line number36 index35 alt1">36</div> <div class="line number37 index36 alt2">37</div> <div class="line number38 index37 alt1">38</div> <div class="line number39 index38 alt2">39</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="js preprocessor">#!/usr/bin/env node</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"><code class="js comments">// load the https module</code></div> <div class="line number4 index3 alt1"> <code class="js keyword">var</code> <code class="js plain">https = require(</code><code class="js string">'https'</code><code class="js plain">);</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="js plain">https.request({</code></div> <div class="line number7 index6 alt2"> <code class="js plain">host: </code><code class="js string">'api.circonus.com'</code><code class="js plain">,</code> </div> <div class="line number8 index7 alt1"> <code class="js plain">path: </code><code class="js string">'/user'</code><code class="js plain">,</code> </div> <div class="line number9 index8 alt2"><code class="js plain">headers: {</code></div> <div class="line number10 index9 alt1"> <code class="js string">'X-Circonus-App-Name'</code><code class="js plain">: </code><code class="js string">'ExampleApp'</code><code class="js plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="js string">'X-Circonus-Auth-Token'</code><code class="js plain">: </code><code class="js string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="js plain">,</code> </div> <div class="line number12 index11 alt1"> <code class="js string">'Accept'</code><code class="js plain">: </code><code class="js string">'application/json'</code> </div> <div class="line number13 index12 alt2"><code class="js plain">}</code></div> <div class="line number14 index13 alt1"> <code class="js plain">}, </code><code class="js keyword">function</code> <code class="js plain">(response) {</code> </div> <div class="line number15 index14 alt2"> </div> <div class="line number16 index15 alt1"><code class="js comments">// collect the body while we're getting chunks of it</code></div> <div class="line number17 index16 alt2"> <code class="js keyword">var</code> <code class="js plain">body = '</code><code class="js string">';</code> </div> <div class="line number18 index17 alt1"> <code class="js string">response.on('</code><code class="js plain">data</code><code class="js string">', function (chunk) { body += chunk; });</code> </div> <div class="line number19 index18 alt2"> </div> <div class="line number20 index19 alt1"> <code class="js string">// once we'</code><code class="js plain">ve got </code><code class="js string">'em all, handle them</code> </div> <div class="line number21 index20 alt2"> <code class="js string">response.on('</code><code class="js plain">end</code><code class="js string">', function () {</code> </div> <div class="line number22 index21 alt1"><code class="js string">// parse the JSON body</code></div> <div class="line number23 index22 alt2"><code class="js string">result = JSON.parse(body);</code></div> <div class="line number24 index23 alt1"> </div> <div class="line number25 index24 alt2"><code class="js string">// handle errors by extracting the code/message from the response</code></div> <div class="line number26 index25 alt1"><code class="js string">if (response.statusCode &lt; 200 || response.statusCode &gt;= 300) {</code></div> <div class="line number27 index26 alt2"><code class="js string">console.log( response.statusCode + ": " </code></div> <div class="line number28 index27 alt1"><code class="js string">+ result.code + " (" + result.message + ")");</code></div> <div class="line number29 index28 alt2"><code class="js string">return;</code></div> <div class="line number30 index29 alt1"><code class="js string">}</code></div> <div class="line number31 index30 alt2"> </div> <div class="line number32 index31 alt1"> <code class="js string">// print out each user'</code><code class="js plain">s details</code> </div> <div class="line number33 index32 alt2"> <code class="js plain">console.log(</code><code class="js string">"Users with access to the account:"</code><code class="js plain">);</code> </div> <div class="line number34 index33 alt1"> <code class="js plain">result.forEach(</code><code class="js keyword">function</code><code class="js plain">(user) {</code> </div> <div class="line number35 index34 alt2"> <code class="js plain">console.log(</code><code class="js string">" * "</code> <code class="js plain">+ user[</code><code class="js string">'_cid'</code><code class="js plain">]</code> </div> <div class="line number36 index35 alt1"> <code class="js plain">+ </code><code class="js string">" ("</code><code class="js plain">+user.firstname + </code><code class="js string">" "</code> <code class="js plain">+ user.lastname + </code><code class="js string">")"</code><code class="js plain">);</code> </div> <div class="line number37 index36 alt2"><code class="js plain">});</code></div> <div class="line number38 index37 alt1"><code class="js plain">});</code></div> <div class="line number39 index38 alt2"><code class="js plain">}).end();</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><h1>API Examples Using PHP</h1><p><br></p><p>GET cid</p><p><br></p><p> </p><div><div class="syntaxhighlighter php" id="highlighter_525686"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="php plain">&lt;?php</code></div> <div class="line number2 index1 alt1"> <code class="php keyword">require_once</code> <code class="php string">'HTTP/Request2.php'</code><code class="php plain">;</code> </div> <div class="line number3 index2 alt2"> </div> <div class="line number4 index3 alt1"> <code class="php variable">$APP</code> <code class="php plain">= </code><code class="php string">"ExampleApp"</code><code class="php plain">;</code> </div> <div class="line number5 index4 alt2"> <code class="php variable">$TOKEN</code> <code class="php plain">= </code><code class="php string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="php plain">;</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="php plain"># talk to the server</code></div> <div class="line number8 index7 alt1"> <code class="php variable">$request</code> <code class="php plain">= </code><code class="php keyword">new</code> <code class="php plain">HTTP_Request2(</code> </div> <div class="line number9 index8 alt2"><code class="php string">"<a href="">https://</a>$APP:$TOKEN@api.circonus.com/user/current"</code></div> <div class="line number10 index9 alt1"><code class="php plain">);</code></div> <div class="line number11 index10 alt2"> <code class="php variable">$request</code><code class="php plain">-&gt;setHeader(</code><code class="php string">"Accept"</code><code class="php plain">,</code><code class="php string">"application/json"</code><code class="php plain">);</code> </div> <div class="line number12 index11 alt1"> <code class="php variable">$response</code> <code class="php plain">= </code><code class="php variable">$request</code><code class="php plain">-&gt;send();</code> </div> <div class="line number13 index12 alt2"> </div> <div class="line number14 index13 alt1"><code class="php plain"># decode the JSON</code></div> <div class="line number15 index14 alt2"> <code class="php variable">$result</code> <code class="php plain">= json_decode(</code><code class="php variable">$response</code><code class="php plain">-&gt;getBody());</code> </div> <div class="line number16 index15 alt1"> </div> <div class="line number17 index16 alt2"> <code class="php plain"># deal with exceptions by accessing the returned json </code><code class="php keyword">and</code> <code class="php plain">throwing why</code> </div> <div class="line number18 index17 alt1"> <code class="php keyword">if</code> <code class="php plain">(!preg_match(</code><code class="php string">"/^2/"</code><code class="php plain">, </code><code class="php variable">$response</code><code class="php plain">-&gt;getStatus())) {</code> </div> <div class="line number19 index18 alt2"> <code class="php keyword">throw</code> <code class="php keyword">new</code> <code class="php plain">Exception(</code> </div> <div class="line number20 index19 alt1"> <code class="php variable">$response</code><code class="php plain">-&gt;getStatus().</code><code class="php string">": "</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;code.</code><code class="php string">" ("</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;message.</code><code class="php string">")"</code> </div> <div class="line number21 index20 alt2"><code class="php plain">);</code></div> <div class="line number22 index21 alt1"><code class="php plain">}</code></div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1"><code class="php plain"># Hello World</code></div> <div class="line number25 index24 alt2"> <code class="php functions">print</code> <code class="php string">"Hello "</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;firstname.</code><code class="php string">" "</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;lastname;</code> </div> <div class="line number26 index25 alt1"><code class="php plain">?&gt;</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>PUT cid</p><p> </p><div><div class="syntaxhighlighter php" id="highlighter_48833"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="php plain">&lt;?php</code></div> <div class="line number2 index1 alt1"> <code class="php keyword">require_once</code> <code class="php string">'HTTP/Request2.php'</code><code class="php plain">;</code> </div> <div class="line number3 index2 alt2"> </div> <div class="line number4 index3 alt1"> <code class="php variable">$APP</code> <code class="php plain">= </code><code class="php string">"ExampleApp"</code><code class="php plain">;</code> </div> <div class="line number5 index4 alt2"> <code class="php variable">$TOKEN</code> <code class="php plain">= </code><code class="php string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="php plain">;</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="php plain"># talk to the server</code></div> <div class="line number8 index7 alt1"> <code class="php variable">$request</code> <code class="php plain">= </code><code class="php keyword">new</code> <code class="php plain">HTTP_Request2(</code> </div> <div class="line number9 index8 alt2"> <code class="php string">"<a href="">https://</a>$APP:$TOKEN@api.circonus.com/user/current"</code><code class="php plain">,</code> </div> <div class="line number10 index9 alt1"><code class="php plain">HTTP_Request2::METHOD_PUT</code></div> <div class="line number11 index10 alt2"><code class="php plain">);</code></div> <div class="line number12 index11 alt1"> <code class="php variable">$request</code><code class="php plain">-&gt;setHeader(</code><code class="php string">"Accept"</code><code class="php plain">,</code><code class="php string">"application/json"</code><code class="php plain">);</code> </div> <div class="line number13 index12 alt2"> <code class="php variable">$request</code><code class="php plain">-&gt;setBody(json_encode(</code><code class="php keyword">array</code><code class="php plain">(</code> </div> <div class="line number14 index13 alt1"> <code class="php string">"firstname"</code> <code class="php plain">=&gt; </code><code class="php string">"Gonzo"</code><code class="php plain">,</code> </div> <div class="line number15 index14 alt2"><code class="php plain">)));</code></div> <div class="line number16 index15 alt1"> <code class="php variable">$response</code> <code class="php plain">= </code><code class="php variable">$request</code><code class="php plain">-&gt;send();</code> </div> <div class="line number17 index16 alt2"> </div> <div class="line number18 index17 alt1"><code class="php plain"># decode the JSON</code></div> <div class="line number19 index18 alt2"> <code class="php variable">$result</code> <code class="php plain">= json_decode(</code><code class="php variable">$response</code><code class="php plain">-&gt;getBody());</code> </div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"> <code class="php plain"># deal with exceptions by accessing the returned json </code><code class="php keyword">and</code> <code class="php plain">throwing why</code> </div> <div class="line number22 index21 alt1"> <code class="php keyword">if</code> <code class="php plain">(!preg_match(</code><code class="php string">"/^2/"</code><code class="php plain">, </code><code class="php variable">$response</code><code class="php plain">-&gt;getStatus())) {</code> </div> <div class="line number23 index22 alt2"> <code class="php keyword">throw</code> <code class="php keyword">new</code> <code class="php plain">Exception(</code> </div> <div class="line number24 index23 alt1"> <code class="php variable">$response</code><code class="php plain">-&gt;getStatus().</code><code class="php string">": "</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;code.</code><code class="php string">" ("</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;message.</code><code class="php string">")"</code> </div> <div class="line number25 index24 alt2"><code class="php plain">);</code></div> <div class="line number26 index25 alt1"><code class="php plain">}</code></div> <div class="line number27 index26 alt2"> </div> <div class="line number28 index27 alt1"><code class="php plain"># And access the updated result returned from the server</code></div> <div class="line number29 index28 alt2"> <code class="php functions">print</code> <code class="php string">"Your first name is now "</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;firstname.</code><code class="php string">"\n"</code><code class="php plain">;</code> </div> <div class="line number30 index29 alt1"><code class="php plain">?&gt;</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>DELETE cid</p><p> </p><div><div class="syntaxhighlighter php" id="highlighter_515720"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="php plain">&lt;?php</code></div> <div class="line number2 index1 alt1"> <code class="php keyword">require_once</code> <code class="php string">'HTTP/Request2.php'</code><code class="php plain">;</code> </div> <div class="line number3 index2 alt2"> </div> <div class="line number4 index3 alt1"> <code class="php variable">$APP</code> <code class="php plain">= </code><code class="php string">"ExampleApp"</code><code class="php plain">;</code> </div> <div class="line number5 index4 alt2"> <code class="php variable">$TOKEN</code> <code class="php plain">= </code><code class="php string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="php plain">;</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="php plain"># talk to the server</code></div> <div class="line number8 index7 alt1"> <code class="php variable">$request</code> <code class="php plain">= </code><code class="php keyword">new</code> <code class="php plain">HTTP_Request2(</code> </div> <div class="line number9 index8 alt2"> <code class="php string">"<a href="">https://</a>$APP:$TOKEN@api.circonus.com/graph/123456"</code><code class="php plain">,</code> </div> <div class="line number10 index9 alt1"><code class="php plain">HTTP_Request2::METHOD_DELETE</code></div> <div class="line number11 index10 alt2"><code class="php plain">);</code></div> <div class="line number12 index11 alt1"> <code class="php variable">$request</code><code class="php plain">-&gt;setHeader(</code><code class="php string">"Accept"</code><code class="php plain">,</code><code class="php string">"application/json"</code><code class="php plain">);</code> </div> <div class="line number13 index12 alt2"> <code class="php variable">$response</code> <code class="php plain">= </code><code class="php variable">$request</code><code class="php plain">-&gt;send();</code> </div> <div class="line number14 index13 alt1"> </div> <div class="line number15 index14 alt2"><code class="php plain"># decode the JSON</code></div> <div class="line number16 index15 alt1"> <code class="php variable">$result</code> <code class="php plain">= json_decode(</code><code class="php variable">$response</code><code class="php plain">-&gt;getBody());</code> </div> <div class="line number17 index16 alt2"> </div> <div class="line number18 index17 alt1"> <code class="php plain"># deal with exceptions by accessing the returned json </code><code class="php keyword">and</code> <code class="php plain">throwing why</code> </div> <div class="line number19 index18 alt2"> <code class="php keyword">if</code> <code class="php plain">(!preg_match(</code><code class="php string">"/^2/"</code><code class="php plain">, </code><code class="php variable">$response</code><code class="php plain">-&gt;getStatus())) {</code> </div> <div class="line number20 index19 alt1"> <code class="php keyword">throw</code> <code class="php keyword">new</code> <code class="php plain">Exception(</code> </div> <div class="line number21 index20 alt2"> <code class="php variable">$response</code><code class="php plain">-&gt;getStatus().</code><code class="php string">": "</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;code.</code><code class="php string">" ("</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;message.</code><code class="php string">")"</code> </div> <div class="line number22 index21 alt1"><code class="php plain">);</code></div> <div class="line number23 index22 alt2"><code class="php plain">}</code></div> <div class="line number24 index23 alt1"> </div> <div class="line number25 index24 alt2"><code class="php plain"># Hello World</code></div> <div class="line number26 index25 alt1"> <code class="php functions">print</code> <code class="php string">"DELETED!\n"</code><code class="php plain">;</code> </div> <div class="line number27 index26 alt2"><code class="php plain">?&gt;</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>POST type</p><p> </p><div><div class="syntaxhighlighter htmlscript" id="highlighter_382884"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"> <code class="htmlscript plain">&lt;?</code><code class="htmlscript keyword">php</code> </div> <div class="line number2 index1 alt1"><code class="htmlscript plain">require_once 'HTTP/Request2.php';</code></div> <div class="line number3 index2 alt2"> </div> <div class="line number4 index3 alt1"> <code class="htmlscript plain">$</code><code class="htmlscript color1">APP</code> <code class="htmlscript plain">= </code><code class="htmlscript string">"ExampleApp"</code><code class="htmlscript plain">;</code> </div> <div class="line number5 index4 alt2"> <code class="htmlscript plain">$</code><code class="htmlscript color1">TOKEN</code> <code class="htmlscript plain">= </code><code class="htmlscript string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="htmlscript plain">;</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="htmlscript plain"># talk to the server</code></div> <div class="line number8 index7 alt1"> <code class="htmlscript plain">$</code><code class="htmlscript color1">request</code> <code class="htmlscript plain">= </code><code class="htmlscript string">new</code> <code class="htmlscript plain">HTTP_Request2(</code> </div> <div class="line number9 index8 alt2"><code class="htmlscript plain">"<a href="">https://</a>$APP:$TOKEN@api.circonus.com/annotation",</code></div> <div class="line number10 index9 alt1"><code class="htmlscript plain">HTTP_Request2::METHOD_POST</code></div> <div class="line number11 index10 alt2"><code class="htmlscript plain">);</code></div> <div class="line number12 index11 alt1"><code class="htmlscript plain">$request-&gt;setHeader("Accept","application/json");</code></div> <div class="line number13 index12 alt2"><code class="htmlscript plain">$request-&gt;setBody(json_encode(array(</code></div> <div class="line number14 index13 alt1"><code class="htmlscript plain">"title" =&gt; "Big Bird's Birthday",</code></div> <div class="line number15 index14 alt2"><code class="htmlscript plain">"description" =&gt; "Big Bird is six (again)",</code></div> <div class="line number16 index15 alt1"><code class="htmlscript plain">"start" =&gt; 1332216000,</code></div> <div class="line number17 index16 alt2"><code class="htmlscript plain">"stop" =&gt; 1332302399,</code></div> <div class="line number18 index17 alt1"><code class="htmlscript plain">)));</code></div> <div class="line number19 index18 alt2"><code class="htmlscript plain">$response = $request-&gt;send();</code></div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"><code class="htmlscript plain"># decode the JSON</code></div> <div class="line number22 index21 alt1"><code class="htmlscript plain">$result = json_decode($response-&gt;getBody());</code></div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1"><code class="htmlscript plain"># deal with exceptions by accessing the returned json and throwing why</code></div> <div class="line number25 index24 alt2"><code class="htmlscript plain">if (!preg_match("/^2/", $response-&gt;getStatus())) {</code></div> <div class="line number26 index25 alt1"><code class="htmlscript plain">throw new Exception(</code></div> <div class="line number27 index26 alt2"><code class="htmlscript plain">$response-&gt;getStatus().": ".$result-&gt;code." (".$result-&gt;message.")"</code></div> <div class="line number28 index27 alt1"><code class="htmlscript plain">);</code></div> <div class="line number29 index28 alt2"><code class="htmlscript plain">}</code></div> <div class="line number30 index29 alt1"> </div> <div class="line number31 index30 alt2"><code class="htmlscript plain"># print out the new cid (and other details)</code></div> <div class="line number32 index31 alt1"><code class="htmlscript plain">print "Created annotation: ".$result-&gt;_cid." (".$result-&gt;title.")\n";</code></div> <div class="line number33 index32 alt2"><code class="htmlscript plain">?&gt;</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>GET type</p><p> </p><div><div class="syntaxhighlighter php" id="highlighter_351730"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="php plain">&lt;?php</code></div> <div class="line number2 index1 alt1"> <code class="php keyword">require_once</code> <code class="php string">'HTTP/Request2.php'</code><code class="php plain">;</code> </div> <div class="line number3 index2 alt2"> </div> <div class="line number4 index3 alt1"> <code class="php variable">$APP</code> <code class="php plain">= </code><code class="php string">"ExampleApp"</code><code class="php plain">;</code> </div> <div class="line number5 index4 alt2"> <code class="php variable">$TOKEN</code> <code class="php plain">= </code><code class="php string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="php plain">;</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="php plain"># talk to the server</code></div> <div class="line number8 index7 alt1"> <code class="php variable">$request</code> <code class="php plain">= </code><code class="php keyword">new</code> <code class="php plain">HTTP_Request2(</code> </div> <div class="line number9 index8 alt2"><code class="php string">"<a href="">https://</a>$APP:$TOKEN@api.circonus.com/user"</code></div> <div class="line number10 index9 alt1"><code class="php plain">);</code></div> <div class="line number11 index10 alt2"> <code class="php variable">$request</code><code class="php plain">-&gt;setHeader(</code><code class="php string">"Accept"</code><code class="php plain">,</code><code class="php string">"application/json"</code><code class="php plain">);</code> </div> <div class="line number12 index11 alt1"> <code class="php variable">$response</code> <code class="php plain">= </code><code class="php variable">$request</code><code class="php plain">-&gt;send();</code> </div> <div class="line number13 index12 alt2"> </div> <div class="line number14 index13 alt1"><code class="php plain"># decode the JSON</code></div> <div class="line number15 index14 alt2"> <code class="php variable">$result</code> <code class="php plain">= json_decode(</code><code class="php variable">$response</code><code class="php plain">-&gt;getBody());</code> </div> <div class="line number16 index15 alt1"> </div> <div class="line number17 index16 alt2"> <code class="php plain"># deal with exceptions by accessing the returned json </code><code class="php keyword">and</code> <code class="php plain">throwing why</code> </div> <div class="line number18 index17 alt1"> <code class="php keyword">if</code> <code class="php plain">(!preg_match(</code><code class="php string">"/^2/"</code><code class="php plain">, </code><code class="php variable">$response</code><code class="php plain">-&gt;getStatus())) {</code> </div> <div class="line number19 index18 alt2"> <code class="php keyword">throw</code> <code class="php keyword">new</code> <code class="php plain">Exception(</code> </div> <div class="line number20 index19 alt1"> <code class="php variable">$response</code><code class="php plain">-&gt;getStatus().</code><code class="php string">": "</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;code.</code><code class="php string">" ("</code><code class="php plain">.</code><code class="php variable">$result</code><code class="php plain">-&gt;message.</code><code class="php string">")"</code> </div> <div class="line number21 index20 alt2"><code class="php plain">);</code></div> <div class="line number22 index21 alt1"><code class="php plain">}</code></div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1"> <code class="php plain"># </code><code class="php functions">print</code> <code class="php plain">out each user's details</code> </div> <div class="line number25 index24 alt2"> <code class="php functions">print</code> <code class="php string">"Users with access to the account:\n"</code><code class="php plain">;</code> </div> <div class="line number26 index25 alt1"> <code class="php keyword">foreach</code> <code class="php plain">(</code><code class="php variable">$result</code> <code class="php keyword">as</code> <code class="php variable">$user</code><code class="php plain">) {</code> </div> <div class="line number27 index26 alt2"> <code class="php functions">print</code> <code class="php string">" * "</code><code class="php plain">.</code><code class="php variable">$user</code><code class="php plain">-&gt;_cid.</code><code class="php string">" ("</code><code class="php plain">.</code><code class="php variable">$user</code><code class="php plain">-&gt;firstname.</code><code class="php string">" "</code><code class="php plain">.</code><code class="php variable">$user</code><code class="php plain">-&gt;lastname.</code><code class="php string">")\n"</code><code class="php plain">;</code> </div> <div class="line number28 index27 alt1"><code class="php plain">}</code></div> <div class="line number29 index28 alt2"><code class="php plain">?&gt;</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><h1>API Examples Using Perl</h1><p><br></p><p>GET cid</p><p> </p><div><div class="syntaxhighlighter perl" id="highlighter_528374"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="perl preprocessor">#!/usr/bin/env perl</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="perl keyword">use</code> <code class="perl plain">strict;</code> </div> <div class="line number4 index3 alt1"> <code class="perl keyword">use</code> <code class="perl plain">warnings;</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="perl comments"># these are core modules since 5.13.9, or install them via the CPAN</code></div> <div class="line number7 index6 alt2"><code class="perl comments"># You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we</code></div> <div class="line number8 index7 alt1"><code class="perl comments"># can talk over https</code></div> <div class="line number9 index8 alt2"> <code class="perl keyword">use</code> <code class="perl plain">HTTP::Tiny;</code> </div> <div class="line number10 index9 alt1"> <code class="perl keyword">use</code> <code class="perl plain">JSON::PP </code><code class="perl string">qw(decode_json)</code><code class="perl plain">;</code> </div> <div class="line number11 index10 alt2"> </div> <div class="line number12 index11 alt1"><code class="perl comments"># create an agent</code></div> <div class="line number13 index12 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$agent</code> <code class="perl plain">= HTTP::Tiny-&gt;new(</code> </div> <div class="line number14 index13 alt1"> <code class="perl string">default_headers</code> <code class="perl plain">=&gt; {</code> </div> <div class="line number15 index14 alt2"> <code class="perl string">'X-Circonus-App-Name'</code> <code class="perl plain">=&gt; </code><code class="perl string">'ExampleApp'</code><code class="perl plain">,</code> </div> <div class="line number16 index15 alt1"> <code class="perl string">'X-Circonus-Auth-Token'</code> <code class="perl plain">=&gt; </code><code class="perl string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="perl plain">,</code> </div> <div class="line number17 index16 alt2"> <code class="perl string">'Accept'</code> <code class="perl plain">=&gt; </code><code class="perl string">"application/json"</code><code class="perl plain">,</code> </div> <div class="line number18 index17 alt1"><code class="perl plain">},</code></div> <div class="line number19 index18 alt2"><code class="perl plain">);</code></div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"><code class="perl comments"># talk to the API over HTTP</code></div> <div class="line number22 index21 alt1"> <code class="perl keyword">my</code> <code class="perl variable">$response</code> <code class="perl plain">= </code><code class="perl variable">$agent</code><code class="perl plain">-&gt;get(</code><code class="perl string">'<a href="https://api.circonus.com/user/current">https://api.circonus.com/user/current</a>'</code><code class="perl plain">);</code> </div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1"><code class="perl comments"># parse the result as JSON</code></div> <div class="line number25 index24 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$result</code> <code class="perl plain">= </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} ? decode_json </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} : {};</code> </div> <div class="line number26 index25 alt1"> </div> <div class="line number27 index26 alt2"><code class="perl comments"># handle errors</code></div> <div class="line number28 index27 alt1"> <code class="perl keyword">unless</code> <code class="perl plain">(</code><code class="perl variable">$response</code><code class="perl plain">-&gt;{success}) {</code> </div> <div class="line number29 index28 alt2"> <code class="perl keyword">die</code> <code class="perl string">"$response-&gt;{status}: $result-&gt;{code} ($result-&gt;{message})\n"</code><code class="perl plain">;</code> </div> <div class="line number30 index29 alt1"><code class="perl plain">}</code></div> <div class="line number31 index30 alt2"> </div> <div class="line number32 index31 alt1"><code class="perl comments"># result holds the data from the server result</code></div> <div class="line number33 index32 alt2"> <code class="perl functions">print</code> <code class="perl string">"Hello $result-&gt;{firstname} $result-&gt;{lastname}\n"</code><code class="perl plain">;</code> </div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>PUT cid</p><p> </p><div><div class="syntaxhighlighter perl" id="highlighter_537352"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> <div class="line number35 index34 alt2">35</div> <div class="line number36 index35 alt1">36</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="perl preprocessor">#!/usr/bin/env perl</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="perl keyword">use</code> <code class="perl plain">strict;</code> </div> <div class="line number4 index3 alt1"> <code class="perl keyword">use</code> <code class="perl plain">warnings;</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="perl comments"># these are core modules since 5.13.9, or install them via the CPAN</code></div> <div class="line number7 index6 alt2"><code class="perl comments"># You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we</code></div> <div class="line number8 index7 alt1"><code class="perl comments"># can talk over https</code></div> <div class="line number9 index8 alt2"> <code class="perl keyword">use</code> <code class="perl plain">HTTP::Tiny;</code> </div> <div class="line number10 index9 alt1"> <code class="perl keyword">use</code> <code class="perl plain">JSON::PP </code><code class="perl string">qw(encode_json decode_json)</code><code class="perl plain">;</code> </div> <div class="line number11 index10 alt2"> </div> <div class="line number12 index11 alt1"><code class="perl comments"># create an agent</code></div> <div class="line number13 index12 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$agent</code> <code class="perl plain">= HTTP::Tiny-&gt;new(</code> </div> <div class="line number14 index13 alt1"> <code class="perl string">default_headers</code> <code class="perl plain">=&gt; {</code> </div> <div class="line number15 index14 alt2"> <code class="perl string">'X-Circonus-App-Name'</code> <code class="perl plain">=&gt; </code><code class="perl string">'ExampleApp'</code><code class="perl plain">,</code> </div> <div class="line number16 index15 alt1"> <code class="perl string">'X-Circonus-Auth-Token'</code> <code class="perl plain">=&gt; </code><code class="perl string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="perl plain">,</code> </div> <div class="line number17 index16 alt2"> <code class="perl string">'Accept'</code> <code class="perl plain">=&gt; </code><code class="perl string">"application/json"</code><code class="perl plain">,</code> </div> <div class="line number18 index17 alt1"><code class="perl plain">},</code></div> <div class="line number19 index18 alt2"><code class="perl plain">);</code></div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"><code class="perl comments"># talk to the API over HTTP</code></div> <div class="line number22 index21 alt1"> <code class="perl keyword">my</code> <code class="perl variable">$response</code> <code class="perl plain">= </code><code class="perl variable">$agent</code><code class="perl plain">-&gt;put(</code><code class="perl string">'<a href="https://api.circonus.com/user/current">https://api.circonus.com/user/current</a>'</code><code class="perl plain">, {</code> </div> <div class="line number23 index22 alt2"> <code class="perl string">content</code> <code class="perl plain">=&gt; encode_json {</code> </div> <div class="line number24 index23 alt1"> <code class="perl string">firstname</code> <code class="perl plain">=&gt; </code><code class="perl string">"Gonzo"</code><code class="perl plain">,</code> </div> <div class="line number25 index24 alt2"><code class="perl plain">},</code></div> <div class="line number26 index25 alt1"><code class="perl plain">});</code></div> <div class="line number27 index26 alt2"> </div> <div class="line number28 index27 alt1"><code class="perl comments"># parse the result as JSON</code></div> <div class="line number29 index28 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$result</code> <code class="perl plain">= </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} ? decode_json </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} : {};</code> </div> <div class="line number30 index29 alt1"> </div> <div class="line number31 index30 alt2"><code class="perl comments"># handle errors</code></div> <div class="line number32 index31 alt1"> <code class="perl keyword">unless</code> <code class="perl plain">(</code><code class="perl variable">$response</code><code class="perl plain">-&gt;{success}) {</code> </div> <div class="line number33 index32 alt2"> <code class="perl keyword">die</code> <code class="perl string">"$response-&gt;{status}: $result-&gt;{code} ($result-&gt;{message})\n"</code><code class="perl plain">;</code> </div> <div class="line number34 index33 alt1"><code class="perl plain">}</code></div> <div class="line number35 index34 alt2"> </div> <div class="line number36 index35 alt1"> <code class="perl functions">print</code> <code class="perl string">"Your first name is now $result-&gt;{firstname}\n"</code><code class="perl plain">;</code> </div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>DELETE cid</p><p> </p><div><div class="syntaxhighlighter perl" id="highlighter_354126"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="perl preprocessor">#!/usr/bin/env perl</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="perl keyword">use</code> <code class="perl plain">strict;</code> </div> <div class="line number4 index3 alt1"> <code class="perl keyword">use</code> <code class="perl plain">warnings;</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="perl comments"># these are core modules since 5.13.9, or install them via the CPAN</code></div> <div class="line number7 index6 alt2"><code class="perl comments"># You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we</code></div> <div class="line number8 index7 alt1"><code class="perl comments"># can talk over https</code></div> <div class="line number9 index8 alt2"> <code class="perl keyword">use</code> <code class="perl plain">HTTP::Tiny;</code> </div> <div class="line number10 index9 alt1"> <code class="perl keyword">use</code> <code class="perl plain">JSON::PP </code><code class="perl string">qw(decode_json)</code><code class="perl plain">;</code> </div> <div class="line number11 index10 alt2"> </div> <div class="line number12 index11 alt1"><code class="perl comments"># create an agent</code></div> <div class="line number13 index12 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$agent</code> <code class="perl plain">= HTTP::Tiny-&gt;new(</code> </div> <div class="line number14 index13 alt1"> <code class="perl string">default_headers</code> <code class="perl plain">=&gt; {</code> </div> <div class="line number15 index14 alt2"> <code class="perl string">'X-Circonus-App-Name'</code> <code class="perl plain">=&gt; </code><code class="perl string">'ExampleApp'</code><code class="perl plain">,</code> </div> <div class="line number16 index15 alt1"> <code class="perl string">'X-Circonus-Auth-Token'</code> <code class="perl plain">=&gt; </code><code class="perl string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="perl plain">,</code> </div> <div class="line number17 index16 alt2"> <code class="perl string">'Accept'</code> <code class="perl plain">=&gt; </code><code class="perl string">"application/json"</code><code class="perl plain">,</code> </div> <div class="line number18 index17 alt1"><code class="perl plain">},</code></div> <div class="line number19 index18 alt2"><code class="perl plain">);</code></div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"><code class="perl comments"># talk to the API over HTTP</code></div> <div class="line number22 index21 alt1"> <code class="perl keyword">my</code> <code class="perl variable">$response</code> <code class="perl plain">= </code><code class="perl variable">$agent</code><code class="perl plain">-&gt;</code><code class="perl functions">delete</code><code class="perl plain">(</code><code class="perl string">'<a href="https://api.circonus.com/graph/123456">https://api.circonus.com/graph/123456</a>'</code><code class="perl plain">);</code> </div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1"><code class="perl comments"># parse the result as JSON</code></div> <div class="line number25 index24 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$result</code> <code class="perl plain">= </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} ? decode_json </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} : {};</code> </div> <div class="line number26 index25 alt1"> </div> <div class="line number27 index26 alt2"><code class="perl comments"># handle errors</code></div> <div class="line number28 index27 alt1"> <code class="perl keyword">unless</code> <code class="perl plain">(</code><code class="perl variable">$response</code><code class="perl plain">-&gt;{success}) {</code> </div> <div class="line number29 index28 alt2"> <code class="perl keyword">die</code> <code class="perl string">"$response-&gt;{status}: $result-&gt;{code} ($result-&gt;{message})\n"</code><code class="perl plain">;</code> </div> <div class="line number30 index29 alt1"><code class="perl plain">}</code></div> <div class="line number31 index30 alt2"> </div> <div class="line number32 index31 alt1"> <code class="perl functions">print</code> <code class="perl string">"DELETED!\n"</code><code class="perl plain">;</code> </div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>POST type</p><p> </p><div><div class="syntaxhighlighter perl" id="highlighter_39196"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> <div class="line number35 index34 alt2">35</div> <div class="line number36 index35 alt1">36</div> <div class="line number37 index36 alt2">37</div> <div class="line number38 index37 alt1">38</div> <div class="line number39 index38 alt2">39</div> <div class="line number40 index39 alt1">40</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="perl preprocessor">#!/usr/bin/env perl</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="perl keyword">use</code> <code class="perl plain">strict;</code> </div> <div class="line number4 index3 alt1"> <code class="perl keyword">use</code> <code class="perl plain">warnings;</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="perl comments"># these are core modules since 5.13.9, or install them via the CPAN</code></div> <div class="line number7 index6 alt2"><code class="perl comments"># You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we</code></div> <div class="line number8 index7 alt1"><code class="perl comments"># can talk over https</code></div> <div class="line number9 index8 alt2"> <code class="perl keyword">use</code> <code class="perl plain">HTTP::Tiny;</code> </div> <div class="line number10 index9 alt1"> <code class="perl keyword">use</code> <code class="perl plain">JSON::PP </code><code class="perl string">qw(encode_json decode_json)</code><code class="perl plain">;</code> </div> <div class="line number11 index10 alt2"> </div> <div class="line number12 index11 alt1"><code class="perl comments"># create an agent</code></div> <div class="line number13 index12 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$agent</code> <code class="perl plain">= HTTP::Tiny-&gt;new(</code> </div> <div class="line number14 index13 alt1"> <code class="perl string">default_headers</code> <code class="perl plain">=&gt; {</code> </div> <div class="line number15 index14 alt2"> <code class="perl string">'X-Circonus-App-Name'</code> <code class="perl plain">=&gt; </code><code class="perl string">'ExampleApp'</code><code class="perl plain">,</code> </div> <div class="line number16 index15 alt1"> <code class="perl string">'X-Circonus-Auth-Token'</code> <code class="perl plain">=&gt; </code><code class="perl string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="perl plain">,</code> </div> <div class="line number17 index16 alt2"> <code class="perl string">'Accept'</code> <code class="perl plain">=&gt; </code><code class="perl string">"application/json"</code><code class="perl plain">,</code> </div> <div class="line number18 index17 alt1"><code class="perl plain">},</code></div> <div class="line number19 index18 alt2"><code class="perl plain">);</code></div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"><code class="perl comments"># talk to the API over HTTP</code></div> <div class="line number22 index21 alt1"> <code class="perl keyword">my</code> <code class="perl variable">$response</code> <code class="perl plain">= </code><code class="perl variable">$agent</code><code class="perl plain">-&gt;post(</code><code class="perl string">'<a href="https://api.circonus.com/annotation">https://api.circonus.com/annotation</a>'</code><code class="perl plain">, {</code> </div> <div class="line number23 index22 alt2"> <code class="perl string">content</code> <code class="perl plain">=&gt; encode_json {</code> </div> <div class="line number24 index23 alt1"> <code class="perl string">title</code> <code class="perl plain">=&gt; </code><code class="perl string">"Big Bird's Birthday"</code><code class="perl plain">,</code> </div> <div class="line number25 index24 alt2"> <code class="perl string">description</code> <code class="perl plain">=&gt; </code><code class="perl string">"Big Bird is six (again)"</code><code class="perl plain">,</code> </div> <div class="line number26 index25 alt1"> <code class="perl string">start</code> <code class="perl plain">=&gt; 1332216000,</code> </div> <div class="line number27 index26 alt2"> <code class="perl string">stop</code> <code class="perl plain">=&gt; 1332302399,</code> </div> <div class="line number28 index27 alt1"><code class="perl plain">}</code></div> <div class="line number29 index28 alt2"><code class="perl plain">});</code></div> <div class="line number30 index29 alt1"> </div> <div class="line number31 index30 alt2"><code class="perl comments"># parse the result as JSON</code></div> <div class="line number32 index31 alt1"> <code class="perl keyword">my</code> <code class="perl variable">$result</code> <code class="perl plain">= </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} ? decode_json </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} : {};</code> </div> <div class="line number33 index32 alt2"> </div> <div class="line number34 index33 alt1"><code class="perl comments"># handle errors</code></div> <div class="line number35 index34 alt2"> <code class="perl keyword">unless</code> <code class="perl plain">(</code><code class="perl variable">$response</code><code class="perl plain">-&gt;{success}) {</code> </div> <div class="line number36 index35 alt1"> <code class="perl keyword">die</code> <code class="perl string">"$response-&gt;{status}: $result-&gt;{code} ($result-&gt;{message})\n"</code><code class="perl plain">;</code> </div> <div class="line number37 index36 alt2"><code class="perl plain">}</code></div> <div class="line number38 index37 alt1"> </div> <div class="line number39 index38 alt2"><code class="perl comments"># print out the new cid (and other details)</code></div> <div class="line number40 index39 alt1"> <code class="perl functions">print</code> <code class="perl string">"Created annotation: $result-&gt;{_cid} ($result-&gt;{title})\n"</code><code class="perl plain">;</code> </div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>GET type</p><p> </p><div><div class="syntaxhighlighter perl" id="highlighter_595238"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> <div class="line number33 index32 alt2">33</div> <div class="line number34 index33 alt1">34</div> <div class="line number35 index34 alt2">35</div> <div class="line number36 index35 alt1">36</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="perl preprocessor">#!/usr/bin/env perl</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="perl keyword">use</code> <code class="perl plain">strict;</code> </div> <div class="line number4 index3 alt1"> <code class="perl keyword">use</code> <code class="perl plain">warnings;</code> </div> <div class="line number5 index4 alt2"> </div> <div class="line number6 index5 alt1"><code class="perl comments"># these are core modules since 5.13.9, or install them via the CPAN</code></div> <div class="line number7 index6 alt2"><code class="perl comments"># You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we</code></div> <div class="line number8 index7 alt1"><code class="perl comments"># can talk over https</code></div> <div class="line number9 index8 alt2"> <code class="perl keyword">use</code> <code class="perl plain">HTTP::Tiny;</code> </div> <div class="line number10 index9 alt1"> <code class="perl keyword">use</code> <code class="perl plain">JSON::PP </code><code class="perl string">qw(decode_json)</code><code class="perl plain">;</code> </div> <div class="line number11 index10 alt2"> </div> <div class="line number12 index11 alt1"><code class="perl comments"># create an agent</code></div> <div class="line number13 index12 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$agent</code> <code class="perl plain">= HTTP::Tiny-&gt;new(</code> </div> <div class="line number14 index13 alt1"> <code class="perl string">default_headers</code> <code class="perl plain">=&gt; {</code> </div> <div class="line number15 index14 alt2"> <code class="perl string">'X-Circonus-App-Name'</code> <code class="perl plain">=&gt; </code><code class="perl string">'ExampleApp'</code><code class="perl plain">,</code> </div> <div class="line number16 index15 alt1"> <code class="perl string">'X-Circonus-Auth-Token'</code> <code class="perl plain">=&gt; </code><code class="perl string">'fb349ef1-91e4-4b05-aaa2-52246b77ea66'</code><code class="perl plain">,</code> </div> <div class="line number17 index16 alt2"> <code class="perl string">'Accept'</code> <code class="perl plain">=&gt; </code><code class="perl string">"application/json"</code><code class="perl plain">,</code> </div> <div class="line number18 index17 alt1"><code class="perl plain">},</code></div> <div class="line number19 index18 alt2"><code class="perl plain">);</code></div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"><code class="perl comments"># talk to the API over HTTP</code></div> <div class="line number22 index21 alt1"> <code class="perl keyword">my</code> <code class="perl variable">$response</code> <code class="perl plain">= </code><code class="perl variable">$agent</code><code class="perl plain">-&gt;get(</code><code class="perl string">'<a href="https://api.circonus.com/user">https://api.circonus.com/user</a>'</code><code class="perl plain">);</code> </div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1"><code class="perl comments"># parse the result as JSON</code></div> <div class="line number25 index24 alt2"> <code class="perl keyword">my</code> <code class="perl variable">$result</code> <code class="perl plain">= </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} ? decode_json </code><code class="perl variable">$response</code><code class="perl plain">-&gt;{content} : {};</code> </div> <div class="line number26 index25 alt1"> </div> <div class="line number27 index26 alt2"><code class="perl comments"># handle errors</code></div> <div class="line number28 index27 alt1"> <code class="perl keyword">unless</code> <code class="perl plain">(</code><code class="perl variable">$response</code><code class="perl plain">-&gt;{success}) {</code> </div> <div class="line number29 index28 alt2"> <code class="perl keyword">die</code> <code class="perl string">"$response-&gt;{status}: $result-&gt;{code} ($result-&gt;{message})\n"</code><code class="perl plain">;</code> </div> <div class="line number30 index29 alt1"><code class="perl plain">}</code></div> <div class="line number31 index30 alt2"> </div> <div class="line number32 index31 alt1"><code class="perl comments"># print out each user's details</code></div> <div class="line number33 index32 alt2"> <code class="perl functions">print</code> <code class="perl string">"Users with access to the account:\n"</code><code class="perl plain">;</code> </div> <div class="line number34 index33 alt1"> <code class="perl keyword">foreach</code> <code class="perl keyword">my</code> <code class="perl variable">$user</code> <code class="perl plain">(@{ </code><code class="perl variable">$result</code> <code class="perl plain">}) {</code> </div> <div class="line number35 index34 alt2"> <code class="perl functions">print</code> <code class="perl string">" * $user-&gt;{_cid} ($user-&gt;{firstname} $user-&gt;{lastname})\n"</code><code class="perl plain">;</code> </div> <div class="line number36 index35 alt1"><code class="perl plain">}</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><h1>API Examples Using Python</h1><p><br></p><p>GET cid</p><p> </p><div><div class="syntaxhighlighter python" id="highlighter_9527"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"> <code class="python keyword">import</code> <code class="python plain">requests;</code> </div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="python keyword">try</code><code class="python plain">:</code> </div> <div class="line number4 index3 alt1"> <code class="python plain">response </code><code class="python keyword">=</code> <code class="python plain">requests.get(</code> </div> <div class="line number5 index4 alt2"> <code class="python string">"<a href="https://api.circonus.com/user/current">https://api.circonus.com/user/current</a>"</code><code class="python plain">,</code> </div> <div class="line number6 index5 alt1"> <code class="python plain">auth</code><code class="python keyword">=</code><code class="python plain">(</code><code class="python string">"ExampleApp"</code><code class="python plain">,</code><code class="python string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="python plain">),</code> </div> <div class="line number7 index6 alt2"> <code class="python plain">headers</code><code class="python keyword">=</code><code class="python plain">{</code><code class="python string">'Accept'</code><code class="python plain">: </code><code class="python string">"application/json"</code><code class="python plain">}</code> </div> <div class="line number8 index7 alt1"><code class="python plain">);</code></div> <div class="line number9 index8 alt2"><code class="python plain">response.raise_for_status()</code></div> <div class="line number10 index9 alt1"> </div> <div class="line number11 index10 alt2"> <code class="python functions">print</code> <code class="python string">"Hello %s %s"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number12 index11 alt1"> <code class="python plain">response.json[</code><code class="python string">'firstname'</code><code class="python plain">],</code> </div> <div class="line number13 index12 alt2"> <code class="python plain">response.json[</code><code class="python string">'lastname'</code><code class="python plain">]</code> </div> <div class="line number14 index13 alt1"><code class="python plain">)</code></div> <div class="line number15 index14 alt2"> </div> <div class="line number16 index15 alt1"><code class="python comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number17 index16 alt2"> <code class="python keyword">except</code> <code class="python plain">requests.exceptions.HTTPError as e:</code> </div> <div class="line number18 index17 alt1"> <code class="python functions">print</code> <code class="python string">"%s: %s (%s)"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number19 index18 alt2"><code class="python plain">e.response.status_code,</code></div> <div class="line number20 index19 alt1"> <code class="python plain">e.response.json[</code><code class="python string">'code'</code><code class="python plain">],</code> </div> <div class="line number21 index20 alt2"> <code class="python plain">e.response.json[</code><code class="python string">'message'</code><code class="python plain">]</code> </div> <div class="line number22 index21 alt1"><code class="python plain">)</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>PUT cid</p><p> </p><div><div class="syntaxhighlighter python" id="highlighter_836122"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"> <code class="python keyword">import</code> <code class="python plain">requests;</code> </div> <div class="line number2 index1 alt1"> <code class="python keyword">import</code> <code class="python plain">json;</code> </div> <div class="line number3 index2 alt2"> </div> <div class="line number4 index3 alt1"> <code class="python keyword">try</code><code class="python plain">:</code> </div> <div class="line number5 index4 alt2"> <code class="python plain">response </code><code class="python keyword">=</code> <code class="python plain">requests.put(</code> </div> <div class="line number6 index5 alt1"> <code class="python string">"<a href="https://api.circonus.com/user/current">https://api.circonus.com/user/current</a>"</code><code class="python plain">,</code> </div> <div class="line number7 index6 alt2"><code class="python plain">json.dumps({</code></div> <div class="line number8 index7 alt1"> <code class="python string">'firstname'</code><code class="python plain">: </code><code class="python string">'Gonzo'</code> </div> <div class="line number9 index8 alt2"><code class="python plain">}),</code></div> <div class="line number10 index9 alt1"> <code class="python plain">auth</code><code class="python keyword">=</code><code class="python plain">(</code><code class="python string">"ExampleApp"</code><code class="python plain">,</code><code class="python string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="python plain">),</code> </div> <div class="line number11 index10 alt2"> <code class="python plain">headers</code><code class="python keyword">=</code><code class="python plain">{</code><code class="python string">'Accept'</code><code class="python plain">: </code><code class="python string">"application/json"</code><code class="python plain">}</code> </div> <div class="line number12 index11 alt1"><code class="python plain">)</code></div> <div class="line number13 index12 alt2"><code class="python plain">response.raise_for_status()</code></div> <div class="line number14 index13 alt1"> </div> <div class="line number15 index14 alt2"> <code class="python functions">print</code> <code class="python string">"Your first name is now %s"</code> <code class="python keyword">%</code> <code class="python plain">response.json[</code><code class="python string">'firstname'</code><code class="python plain">]</code> </div> <div class="line number16 index15 alt1"> </div> <div class="line number17 index16 alt2"><code class="python comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number18 index17 alt1"> <code class="python keyword">except</code> <code class="python plain">requests.exceptions.HTTPError as e:</code> </div> <div class="line number19 index18 alt2"> <code class="python functions">print</code> <code class="python string">"%s: %s (%s)"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number20 index19 alt1"><code class="python plain">e.response.status_code,</code></div> <div class="line number21 index20 alt2"> <code class="python plain">e.response.json[</code><code class="python string">'code'</code><code class="python plain">],</code> </div> <div class="line number22 index21 alt1"> <code class="python plain">e.response.json[</code><code class="python string">'message'</code><code class="python plain">]</code> </div> <div class="line number23 index22 alt2"><code class="python plain">)</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>DELETE cid</p><p> </p><div><div class="syntaxhighlighter python" id="highlighter_257139"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"> <code class="python keyword">import</code> <code class="python plain">requests;</code> </div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="python keyword">try</code><code class="python plain">:</code> </div> <div class="line number4 index3 alt1"> <code class="python plain">response </code><code class="python keyword">=</code> <code class="python plain">requests.delete(</code> </div> <div class="line number5 index4 alt2"> <code class="python string">"<a href="https://api.circonus.com/graph/123456">https://api.circonus.com/graph/123456</a>"</code><code class="python plain">,</code> </div> <div class="line number6 index5 alt1"> <code class="python plain">auth</code><code class="python keyword">=</code><code class="python plain">(</code><code class="python string">"ExampleApp"</code><code class="python plain">,</code><code class="python string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="python plain">),</code> </div> <div class="line number7 index6 alt2"> <code class="python plain">headers</code><code class="python keyword">=</code><code class="python plain">{</code><code class="python string">'Accept'</code><code class="python plain">: </code><code class="python string">"application/json"</code><code class="python plain">}</code> </div> <div class="line number8 index7 alt1"><code class="python plain">)</code></div> <div class="line number9 index8 alt2"><code class="python plain">response.raise_for_status()</code></div> <div class="line number10 index9 alt1"> </div> <div class="line number11 index10 alt2"> <code class="python functions">print</code> <code class="python string">"DELETED!"</code> </div> <div class="line number12 index11 alt1"> </div> <div class="line number13 index12 alt2"><code class="python comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number14 index13 alt1"> <code class="python keyword">except</code> <code class="python plain">requests.exceptions.HTTPError as e:</code> </div> <div class="line number15 index14 alt2"> <code class="python functions">print</code> <code class="python string">"%s: %s (%s)"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number16 index15 alt1"><code class="python plain">e.response.status_code,</code></div> <div class="line number17 index16 alt2"> <code class="python plain">e.response.json[</code><code class="python string">'code'</code><code class="python plain">],</code> </div> <div class="line number18 index17 alt1"> <code class="python plain">e.response.json[</code><code class="python string">'message'</code><code class="python plain">]</code> </div> <div class="line number19 index18 alt2"><code class="python plain">)</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>POST type</p><p> </p><div><div class="syntaxhighlighter python" id="highlighter_209187"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"> <code class="python keyword">import</code> <code class="python plain">requests;</code> </div> <div class="line number2 index1 alt1"> <code class="python keyword">import</code> <code class="python plain">json;</code> </div> <div class="line number3 index2 alt2"> </div> <div class="line number4 index3 alt1"> <code class="python keyword">try</code><code class="python plain">:</code> </div> <div class="line number5 index4 alt2"> <code class="python plain">response </code><code class="python keyword">=</code> <code class="python plain">requests.post(</code> </div> <div class="line number6 index5 alt1"> <code class="python string">"<a href="https://api.circonus.com/annotation">https://api.circonus.com/annotation</a>"</code><code class="python plain">,</code> </div> <div class="line number7 index6 alt2"><code class="python plain">json.dumps({</code></div> <div class="line number8 index7 alt1"> <code class="python string">"title"</code><code class="python plain">: </code><code class="python string">"Big Bird's Birthday"</code><code class="python plain">,</code> </div> <div class="line number9 index8 alt2"> <code class="python string">"description"</code><code class="python plain">: </code><code class="python string">"Big Bird is six (again)"</code><code class="python plain">,</code> </div> <div class="line number10 index9 alt1"> <code class="python string">"start"</code><code class="python plain">: </code><code class="python value">1332216000</code><code class="python plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="python string">"stop"</code><code class="python plain">: </code><code class="python value">1332302399</code> </div> <div class="line number12 index11 alt1"><code class="python plain">}),</code></div> <div class="line number13 index12 alt2"> <code class="python plain">auth</code><code class="python keyword">=</code><code class="python plain">(</code><code class="python string">"ExampleApp"</code><code class="python plain">,</code><code class="python string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="python plain">),</code> </div> <div class="line number14 index13 alt1"> <code class="python plain">headers</code><code class="python keyword">=</code><code class="python plain">{</code><code class="python string">'Accept'</code><code class="python plain">: </code><code class="python string">"application/json"</code><code class="python plain">}</code> </div> <div class="line number15 index14 alt2"><code class="python plain">)</code></div> <div class="line number16 index15 alt1"><code class="python plain">response.raise_for_status()</code></div> <div class="line number17 index16 alt2"> </div> <div class="line number18 index17 alt1"> <code class="python functions">print</code> <code class="python string">"Created annotation: %s (%s)"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number19 index18 alt2"> <code class="python plain">response.json[</code><code class="python string">"_cid"</code><code class="python plain">],</code> </div> <div class="line number20 index19 alt1"> <code class="python plain">response.json[</code><code class="python string">"title"</code><code class="python plain">]</code> </div> <div class="line number21 index20 alt2"><code class="python plain">)</code></div> <div class="line number22 index21 alt1"> </div> <div class="line number23 index22 alt2"><code class="python comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number24 index23 alt1"> <code class="python keyword">except</code> <code class="python plain">requests.exceptions.HTTPError as e:</code> </div> <div class="line number25 index24 alt2"> <code class="python functions">print</code> <code class="python string">"%s: %s (%s)"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number26 index25 alt1"><code class="python plain">e.response.status_code,</code></div> <div class="line number27 index26 alt2"> <code class="python plain">e.response.json[</code><code class="python string">'code'</code><code class="python plain">],</code> </div> <div class="line number28 index27 alt1"> <code class="python plain">e.response.json[</code><code class="python string">'message'</code><code class="python plain">]</code> </div> <div class="line number29 index28 alt2"><code class="python plain">)</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>GET type</p><p> </p><div><div class="syntaxhighlighter python" id="highlighter_635536"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"> <code class="python keyword">import</code> <code class="python plain">requests;</code> </div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="python keyword">try</code><code class="python plain">:</code> </div> <div class="line number4 index3 alt1"> <code class="python plain">response </code><code class="python keyword">=</code> <code class="python plain">requests.get(</code> </div> <div class="line number5 index4 alt2"> <code class="python string">"<a href="https://api.circonus.com/user">https://api.circonus.com/user</a>"</code><code class="python plain">,</code> </div> <div class="line number6 index5 alt1"> <code class="python plain">auth</code><code class="python keyword">=</code><code class="python plain">(</code><code class="python string">"ExampleApp"</code><code class="python plain">,</code><code class="python string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="python plain">),</code> </div> <div class="line number7 index6 alt2"> <code class="python plain">headers</code><code class="python keyword">=</code><code class="python plain">{</code><code class="python string">'Accept'</code><code class="python plain">: </code><code class="python string">"application/json"</code><code class="python plain">}</code> </div> <div class="line number8 index7 alt1"><code class="python plain">);</code></div> <div class="line number9 index8 alt2"><code class="python plain">response.raise_for_status()</code></div> <div class="line number10 index9 alt1"> </div> <div class="line number11 index10 alt2"><code class="python comments"># print out each user's details</code></div> <div class="line number12 index11 alt1"> <code class="python functions">print</code> <code class="python string">"Users with access to the account:"</code> </div> <div class="line number13 index12 alt2"> <code class="python keyword">for</code> <code class="python plain">user </code><code class="python keyword">in</code> <code class="python plain">response.json:</code> </div> <div class="line number14 index13 alt1"> <code class="python functions">print</code> <code class="python string">" * %s (%s %s)"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number15 index14 alt2"> <code class="python plain">user[</code><code class="python string">'email'</code><code class="python plain">],</code> </div> <div class="line number16 index15 alt1"> <code class="python plain">user[</code><code class="python string">'firstname'</code><code class="python plain">],</code> </div> <div class="line number17 index16 alt2"> <code class="python plain">user[</code><code class="python string">'lastname'</code><code class="python plain">],</code> </div> <div class="line number18 index17 alt1"><code class="python plain">)</code></div> <div class="line number19 index18 alt2"> </div> <div class="line number20 index19 alt1"><code class="python comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number21 index20 alt2"> <code class="python keyword">except</code> <code class="python plain">requests.exceptions.HTTPError as e:</code> </div> <div class="line number22 index21 alt1"> <code class="python functions">print</code> <code class="python string">"%s: %s (%s)"</code> <code class="python keyword">%</code> <code class="python plain">(</code> </div> <div class="line number23 index22 alt2"><code class="python plain">e.response.status_code,</code></div> <div class="line number24 index23 alt1"> <code class="python plain">e.response.json[</code><code class="python string">'code'</code><code class="python plain">],</code> </div> <div class="line number25 index24 alt2"> <code class="python plain">e.response.json[</code><code class="python string">'message'</code><code class="python plain">]</code> </div> <div class="line number26 index25 alt1"><code class="python plain">)</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><h1>API Examples Using Ruby</h1><p><br></p><p>GET cid</p><p> </p><div><div class="syntaxhighlighter ruby" id="highlighter_637564"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="ruby comments">#!/usr/bin/ruby</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rubygems'</code> </div> <div class="line number4 index3 alt1"> <code class="ruby plain">require </code><code class="ruby string">'json'</code> </div> <div class="line number5 index4 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rest_client'</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="ruby comments"># setup client</code></div> <div class="line number8 index7 alt1"> <code class="ruby plain">circonus = RestClient::Resource.</code><code class="ruby keyword">new</code><code class="ruby plain">(</code><code class="ruby string">"<a href="https://api.circonus.com">https://api.circonus.com</a>"</code><code class="ruby plain">, </code><code class="ruby color2">:headers</code> <code class="ruby plain">=&gt; {</code> </div> <div class="line number9 index8 alt2"> <code class="ruby color2">:x_circonus_app_name</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"ExampleApp"</code><code class="ruby plain">,</code> </div> <div class="line number10 index9 alt1"> <code class="ruby color2">:x_circonus_auth_token</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="ruby plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="ruby color2">:accept</code> <code class="ruby plain">=&gt; </code><code class="ruby string">'application/json'</code><code class="ruby plain">,</code> </div> <div class="line number12 index11 alt1"><code class="ruby plain">})</code></div> <div class="line number13 index12 alt2"> </div> <div class="line number14 index13 alt1"><code class="ruby keyword">begin</code></div> <div class="line number15 index14 alt2"><code class="ruby comments"># get and parse</code></div> <div class="line number16 index15 alt1"> <code class="ruby plain">response = circonus[</code><code class="ruby string">"/user/current"</code><code class="ruby plain">].get;</code> </div> <div class="line number17 index16 alt2"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(response);</code> </div> <div class="line number18 index17 alt1"> </div> <div class="line number19 index18 alt2"><code class="ruby comments"># print out the result</code></div> <div class="line number20 index19 alt1"> <code class="ruby plain">puts </code><code class="ruby string">"Hello #{result['firstname']} #{result['lastname']}"</code><code class="ruby plain">;</code> </div> <div class="line number21 index20 alt2"> </div> <div class="line number22 index21 alt1"> <code class="ruby keyword">rescue</code> <code class="ruby plain">RestClient::</code><code class="ruby color1">Exception</code> <code class="ruby plain">=&gt; ex</code> </div> <div class="line number23 index22 alt2"><code class="ruby comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number24 index23 alt1"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(ex.http_body)</code> </div> <div class="line number25 index24 alt2"> <code class="ruby plain">puts </code><code class="ruby string">"#{ex.http_code}: #{result['code']} (#{result['message']})"</code> </div> <div class="line number26 index25 alt1"><code class="ruby keyword">end</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>PUT cid</p><p> </p><div><div class="syntaxhighlighter ruby" id="highlighter_345288"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="ruby comments">#!/usr/bin/ruby</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rubygems'</code> </div> <div class="line number4 index3 alt1"> <code class="ruby plain">require </code><code class="ruby string">'json'</code> </div> <div class="line number5 index4 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rest_client'</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="ruby comments"># setup client</code></div> <div class="line number8 index7 alt1"> <code class="ruby plain">circonus = RestClient::Resource.</code><code class="ruby keyword">new</code><code class="ruby plain">(</code><code class="ruby string">"<a href="https://api.circonus.com">https://api.circonus.com</a>"</code><code class="ruby plain">, </code><code class="ruby color2">:headers</code> <code class="ruby plain">=&gt; {</code> </div> <div class="line number9 index8 alt2"> <code class="ruby color2">:x_circonus_app_name</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"ExampleApp"</code><code class="ruby plain">,</code> </div> <div class="line number10 index9 alt1"> <code class="ruby color2">:x_circonus_auth_token</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="ruby plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="ruby color2">:accept</code> <code class="ruby plain">=&gt; </code><code class="ruby string">'application/json'</code><code class="ruby plain">,</code> </div> <div class="line number12 index11 alt1"><code class="ruby plain">})</code></div> <div class="line number13 index12 alt2"> </div> <div class="line number14 index13 alt1"><code class="ruby keyword">begin</code></div> <div class="line number15 index14 alt2"><code class="ruby comments"># put and parse the updated object</code></div> <div class="line number16 index15 alt1"> <code class="ruby plain">response = circonus[</code><code class="ruby string">"/user/current"</code><code class="ruby plain">].put(</code> </div> <div class="line number17 index16 alt2"> <code class="ruby plain">{ </code><code class="ruby color2">:firstname</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"Gonzo"</code> <code class="ruby plain">}.to_json()</code> </div> <div class="line number18 index17 alt1"><code class="ruby plain">);</code></div> <div class="line number19 index18 alt2"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(response);</code> </div> <div class="line number20 index19 alt1"> </div> <div class="line number21 index20 alt2"> <code class="ruby plain">puts </code><code class="ruby string">"Your first name is now #{result['firstname']}"</code><code class="ruby plain">;</code> </div> <div class="line number22 index21 alt1"> </div> <div class="line number23 index22 alt2"> <code class="ruby keyword">rescue</code> <code class="ruby plain">RestClient::</code><code class="ruby color1">Exception</code> <code class="ruby plain">=&gt; ex</code> </div> <div class="line number24 index23 alt1"><code class="ruby comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number25 index24 alt2"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(ex.http_body)</code> </div> <div class="line number26 index25 alt1"> <code class="ruby plain">puts </code><code class="ruby string">"#{ex.http_code}: #{result['code']} (#{result['message']})"</code> </div> <div class="line number27 index26 alt2"><code class="ruby keyword">end</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>DELETE cid</p><p> </p><div><div class="syntaxhighlighter ruby" id="highlighter_499500"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="ruby comments">#!/usr/bin/ruby</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rubygems'</code> </div> <div class="line number4 index3 alt1"> <code class="ruby plain">require </code><code class="ruby string">'json'</code> </div> <div class="line number5 index4 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rest_client'</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="ruby comments"># setup client</code></div> <div class="line number8 index7 alt1"> <code class="ruby plain">circonus = RestClient::Resource.</code><code class="ruby keyword">new</code><code class="ruby plain">(</code><code class="ruby string">"<a href="https://api.circonus.com">https://api.circonus.com</a>"</code><code class="ruby plain">, </code><code class="ruby color2">:headers</code> <code class="ruby plain">=&gt; {</code> </div> <div class="line number9 index8 alt2"> <code class="ruby color2">:x_circonus_app_name</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"ExampleApp"</code><code class="ruby plain">,</code> </div> <div class="line number10 index9 alt1"> <code class="ruby color2">:x_circonus_auth_token</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="ruby plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="ruby color2">:accept</code> <code class="ruby plain">=&gt; </code><code class="ruby string">'application/json'</code><code class="ruby plain">,</code> </div> <div class="line number12 index11 alt1"><code class="ruby plain">})</code></div> <div class="line number13 index12 alt2"> </div> <div class="line number14 index13 alt1"><code class="ruby keyword">begin</code></div> <div class="line number15 index14 alt2"><code class="ruby comments"># delete</code></div> <div class="line number16 index15 alt1"> <code class="ruby plain">response = circonus[</code><code class="ruby string">"/graph/123456"</code><code class="ruby plain">].delete;</code> </div> <div class="line number17 index16 alt2"> </div> <div class="line number18 index17 alt1"> <code class="ruby plain">puts </code><code class="ruby string">"DELETED!"</code> </div> <div class="line number19 index18 alt2"> </div> <div class="line number20 index19 alt1"> <code class="ruby keyword">rescue</code> <code class="ruby plain">RestClient::</code><code class="ruby color1">Exception</code> <code class="ruby plain">=&gt; ex</code> </div> <div class="line number21 index20 alt2"><code class="ruby comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number22 index21 alt1"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(ex.http_body)</code> </div> <div class="line number23 index22 alt2"> <code class="ruby plain">puts </code><code class="ruby string">"#{ex.http_code}: #{result['code']} (#{result['message']})"</code> </div> <div class="line number24 index23 alt1"><code class="ruby keyword">end</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>POST type</p><p> </p><div><div class="syntaxhighlighter ruby" id="highlighter_16168"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> <div class="line number30 index29 alt1">30</div> <div class="line number31 index30 alt2">31</div> <div class="line number32 index31 alt1">32</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="ruby comments">#!/usr/bin/ruby</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rubygems'</code> </div> <div class="line number4 index3 alt1"> <code class="ruby plain">require </code><code class="ruby string">'json'</code> </div> <div class="line number5 index4 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rest_client'</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="ruby comments"># setup client</code></div> <div class="line number8 index7 alt1"> <code class="ruby plain">circonus = RestClient::Resource.</code><code class="ruby keyword">new</code><code class="ruby plain">(</code><code class="ruby string">"<a href="https://api.circonus.com">https://api.circonus.com</a>"</code><code class="ruby plain">, </code><code class="ruby color2">:headers</code> <code class="ruby plain">=&gt; {</code> </div> <div class="line number9 index8 alt2"> <code class="ruby color2">:x_circonus_app_name</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"ExampleApp"</code><code class="ruby plain">,</code> </div> <div class="line number10 index9 alt1"> <code class="ruby color2">:x_circonus_auth_token</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="ruby plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="ruby color2">:accept</code> <code class="ruby plain">=&gt; </code><code class="ruby string">'application/json'</code><code class="ruby plain">,</code> </div> <div class="line number12 index11 alt1"><code class="ruby plain">})</code></div> <div class="line number13 index12 alt2"> </div> <div class="line number14 index13 alt1"><code class="ruby keyword">begin</code></div> <div class="line number15 index14 alt2"><code class="ruby comments"># put and parse the updated object</code></div> <div class="line number16 index15 alt1"> <code class="ruby plain">response = circonus[</code><code class="ruby string">"/annotation"</code><code class="ruby plain">].post(</code> </div> <div class="line number17 index16 alt2"><code class="ruby plain">{</code></div> <div class="line number18 index17 alt1"> <code class="ruby color2">:title</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"Big Bird's Birthday"</code><code class="ruby plain">,</code> </div> <div class="line number19 index18 alt2"> <code class="ruby color2">:description</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"Big Bird is six (again)"</code><code class="ruby plain">,</code> </div> <div class="line number20 index19 alt1"> <code class="ruby color2">:start</code> <code class="ruby plain">=&gt; </code><code class="ruby constants">1332216000</code><code class="ruby plain">,</code> </div> <div class="line number21 index20 alt2"> <code class="ruby color2">:stop</code> <code class="ruby plain">=&gt; </code><code class="ruby constants">1332302399</code><code class="ruby plain">,</code> </div> <div class="line number22 index21 alt1"><code class="ruby plain">}.to_json()</code></div> <div class="line number23 index22 alt2"><code class="ruby plain">);</code></div> <div class="line number24 index23 alt1"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(response);</code> </div> <div class="line number25 index24 alt2"> </div> <div class="line number26 index25 alt1"> <code class="ruby plain">puts </code><code class="ruby string">"Created annotation: #{result['_cid']} (#{result['title']})"</code><code class="ruby plain">;</code> </div> <div class="line number27 index26 alt2"> </div> <div class="line number28 index27 alt1"> <code class="ruby keyword">rescue</code> <code class="ruby plain">RestClient::</code><code class="ruby color1">Exception</code> <code class="ruby plain">=&gt; ex</code> </div> <div class="line number29 index28 alt2"><code class="ruby comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number30 index29 alt1"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(ex.http_body)</code> </div> <div class="line number31 index30 alt2"> <code class="ruby plain">puts </code><code class="ruby string">"#{ex.http_code}: #{result['code']} (#{result['message']})"</code> </div> <div class="line number32 index31 alt1"><code class="ruby keyword">end</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p>GET type</p><p> </p><div><div class="syntaxhighlighter ruby" id="highlighter_485239"><div class="toolbar1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr> <td class="gutter"> <div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="line number9 index8 alt2">9</div> <div class="line number10 index9 alt1">10</div> <div class="line number11 index10 alt2">11</div> <div class="line number12 index11 alt1">12</div> <div class="line number13 index12 alt2">13</div> <div class="line number14 index13 alt1">14</div> <div class="line number15 index14 alt2">15</div> <div class="line number16 index15 alt1">16</div> <div class="line number17 index16 alt2">17</div> <div class="line number18 index17 alt1">18</div> <div class="line number19 index18 alt2">19</div> <div class="line number20 index19 alt1">20</div> <div class="line number21 index20 alt2">21</div> <div class="line number22 index21 alt1">22</div> <div class="line number23 index22 alt2">23</div> <div class="line number24 index23 alt1">24</div> <div class="line number25 index24 alt2">25</div> <div class="line number26 index25 alt1">26</div> <div class="line number27 index26 alt2">27</div> <div class="line number28 index27 alt1">28</div> <div class="line number29 index28 alt2">29</div> </td> <td class="code"><div class="container"> <div class="line number1 index0 alt2"><code class="ruby comments">#!/usr/bin/ruby</code></div> <div class="line number2 index1 alt1"> </div> <div class="line number3 index2 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rubygems'</code> </div> <div class="line number4 index3 alt1"> <code class="ruby plain">require </code><code class="ruby string">'json'</code> </div> <div class="line number5 index4 alt2"> <code class="ruby plain">require </code><code class="ruby string">'rest_client'</code> </div> <div class="line number6 index5 alt1"> </div> <div class="line number7 index6 alt2"><code class="ruby comments"># setup client</code></div> <div class="line number8 index7 alt1"> <code class="ruby plain">circonus = RestClient::Resource.</code><code class="ruby keyword">new</code><code class="ruby plain">(</code><code class="ruby string">"<a href="https://api.circonus.com">https://api.circonus.com</a>"</code><code class="ruby plain">, </code><code class="ruby color2">:headers</code> <code class="ruby plain">=&gt; {</code> </div> <div class="line number9 index8 alt2"> <code class="ruby color2">:x_circonus_app_name</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"ExampleApp"</code><code class="ruby plain">,</code> </div> <div class="line number10 index9 alt1"> <code class="ruby color2">:x_circonus_auth_token</code> <code class="ruby plain">=&gt; </code><code class="ruby string">"fb349ef1-91e4-4b05-aaa2-52246b77ea66"</code><code class="ruby plain">,</code> </div> <div class="line number11 index10 alt2"> <code class="ruby color2">:accept</code> <code class="ruby plain">=&gt; </code><code class="ruby string">'application/json'</code><code class="ruby plain">,</code> </div> <div class="line number12 index11 alt1"><code class="ruby plain">})</code></div> <div class="line number13 index12 alt2"> </div> <div class="line number14 index13 alt1"><code class="ruby keyword">begin</code></div> <div class="line number15 index14 alt2"><code class="ruby comments"># get and parse</code></div> <div class="line number16 index15 alt1"> <code class="ruby plain">response = circonus[</code><code class="ruby string">"/user"</code><code class="ruby plain">].get;</code> </div> <div class="line number17 index16 alt2"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(response);</code> </div> <div class="line number18 index17 alt1"> </div> <div class="line number19 index18 alt2"><code class="ruby comments"># print out each user's details</code></div> <div class="line number20 index19 alt1"> <code class="ruby plain">puts </code><code class="ruby string">"Users with access to the account:"</code><code class="ruby plain">;</code> </div> <div class="line number21 index20 alt2"> <code class="ruby plain">result.</code><code class="ruby keyword">each</code> <code class="ruby plain">{ |user|</code> </div> <div class="line number22 index21 alt1"> <code class="ruby plain">puts </code><code class="ruby string">" * #{user['_cid']} (#{user['firstname']} #{user['lastname']})\n"</code><code class="ruby plain">;</code> </div> <div class="line number23 index22 alt2"><code class="ruby plain">}</code></div> <div class="line number24 index23 alt1"> </div> <div class="line number25 index24 alt2"> <code class="ruby keyword">rescue</code> <code class="ruby plain">RestClient::</code><code class="ruby color1">Exception</code> <code class="ruby plain">=&gt; ex</code> </div> <div class="line number26 index25 alt1"><code class="ruby comments"># deal with exceptions by accessing the returned json and printing out why</code></div> <div class="line number27 index26 alt2"> <code class="ruby plain">result = </code><code class="ruby constants">JSON</code><code class="ruby plain">.parse(ex.http_body)</code> </div> <div class="line number28 index27 alt1"> <code class="ruby plain">puts </code><code class="ruby string">"#{ex.http_code}: #{result['code']} (#{result['message']})"</code> </div> <div class="line number29 index28 alt2"><code class="ruby keyword">end</code></div> </div></td> </tr></tbody></table></div></div></div><p> </p><p><br></p> 6000191060 353 6000055866 2017-09-18T17:50:51-04:00 6003235491 2 2 1 1 Example API Calls 2015-09-04T16:27:31-04:00 6003235491 1 2015-09-24T16:15:40-04:00 0 1 Following up from the blog post here, here's a step by step what I did to get things to work: Went to github, downloaded https://github.com/circonus-labs/python-circonusapi and https://github.com/circonus-labs/circonusvi. Created my .circonusapirc file in ~/ , substituting my account_name for "foo" and the API key I created at https://login.circonus.com/user/tokens. cd'ed to the python-circonusapi-master directory and ran "sudo ./setup.py install". cd'ed to the circonusvi-master. Ran ./circonusvi.py and got a nasty error ending with "TokenNotValidated". Went back to https://login.circonus.com/user/tokens, refreshed the page, and clicked on "Allow Access" Re-ran ./circonusvi.py. And whammo - it works! Got the full list of stuff from my account. Note you can use different editors - very cool - with the -E option (nano or emacs editors are options). You can play around with the -e option to filter on specific things your interested in, and the other options. The line of code that does the matching: https://github.com/circonus-labs/circonusvi/blob/master/circonusvi.py#L1931, which does a regular expression match. The engine is python regular expressions, and documentation on how it works is available at http://docs.python.org/2/library/re.html#regular-expression-syntax and http://docs.python.org/2/library/re.html#re.RegexObject.search. Let me know if you have any questions -christian.madsen@circonus.com. <p style="margin-bottom: 10px; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;">Following up from the blog post <a href="http://www.circonus.com/circonusvi/" style="color: rgb(59, 115, 185);">here</a>, here's a step by step what I did to get things to work:</p> <p style="margin-bottom: 10px; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;"></p> <ol> <li> <span style="font-size: 14px;">Went to github, downloaded </span><a href="https://github.com/circonus-labs/python-circonusapi" style="font-size: 14px; color: rgb(59, 115, 185); background-color: rgb(255, 255, 255);"></a><a href="https://github.com/circonus-labs/python-circonusapi" style="font-size: 14px; color: rgb(59, 115, 185); background-color: rgb(255, 255, 255);">https://github.com/circonus-labs/python-circonusapi</a><span style="font-size: 14px;"> and </span><a href="https://github.com/circonus-labs/circonusvi" style="font-size: 14px; color: rgb(59, 115, 185); background-color: rgb(255, 255, 255);">https://github.com/circonus-labs/circonusvi</a><span style="font-size: 14px;">.</span><br> </li> <li> <span style="font-size: 14px;">Created my .circonusapirc file in ~/ , substituting my account_name for "foo" and the API key I created at </span><a href="https://login.circonus.com/user/tokens" style="font-size: 14px; color: rgb(59, 115, 185); background-color: rgb(255, 255, 255);">https://login.circonus.com/user/tokens</a>.<br> </li> <li> <span style="font-size: 14px;">cd'ed to the python-circonusapi-master directory and ran "sudo ./setup.py install".</span><br> </li> <li> <span style="font-size: 14px;">cd'ed to the circonusvi-master.</span><br> </li> <li> <span style="font-size: 14px;">Ran ./circonusvi.py and got a nasty error ending with "TokenNotValidated".</span><br> </li> <li> <span style="font-size: 14px;">Went back to </span><a href="https://login.circonus.com/user/tokens" style="font-size: 14px; color: rgb(59, 115, 185); background-color: rgb(255, 255, 255);"></a><a href="https://login.circonus.com/user/tokens" style="font-size: 14px; color: rgb(59, 115, 185); background-color: rgb(255, 255, 255);">https://login.circonus.com/user/tokens</a><span style="font-size: 14px;">, refreshed the page, and clicked on "Allow Access"</span><br> </li> <li> <span style="font-size: 14px;">Re-ran ./circonusvi.py. And whammo - it works! Got the full list of stuff from my account.</span><br> </li> </ol> <p style="margin-bottom: 10px; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;">Note you can use different editors - very cool - with the -E option (nano or emacs editors are options). You can play around with the -e option to filter on specific things your interested in, and the other options.</p> <p style="margin-bottom: 10px; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;">The line of code that does the matching: <a href="https://github.com/circonus-labs/circonusvi/blob/master/circonusvi.py#L193" style="color: rgb(59, 115, 185);">https://github.com/circonus-labs/circonusvi/blob/master/circonusvi.py#L1931</a>, which does a regular expression match. The engine is python regular expressions, and documentation on how it works is available at <a href="http://docs.python.org/2/library/re.html#regular-expression-syntax" style="color: rgb(59, 115, 185);"></a><a href="http://docs.python.org/2/library/re.html#regular-expression-syntax" style="color: rgb(59, 115, 185);">http://docs.python.org/2/library/re.html#regular-expression-syntax</a> and <a href="http://docs.python.org/2/library/re.html#re.RegexObject.search" style="color: rgb(59, 115, 185);"></a><a href="http://docs.python.org/2/library/re.html#re.RegexObject.search" style="color: rgb(59, 115, 185);">http://docs.python.org/2/library/re.html#re.RegexObject.search</a>.</p> <p style="margin-bottom: 10px; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;">Let me know if you have any questions <span>-</span><a href="mailto:christian.madsen@circonus.com" style="color: rgb(59, 115, 185); background-color: rgb(255, 255, 255);">christian.madsen@circonus.com</a><span>.</span></p> 6000191060 99 6000066883 2015-10-29T21:40:07-04:00 6003235491 3 2 0 1 Circonusvi Tool - Quick How To Guide 2015-09-24T16:15:40-04:00 6003235491