Skip to content

Instantly share code, notes, and snippets.

@leoken
Created October 12, 2012 07:51
Show Gist options
  • Save leoken/3877849 to your computer and use it in GitHub Desktop.
Save leoken/3877849 to your computer and use it in GitHub Desktop.
Example code to use the Pingdom API
<?php
// Init cURL
$curl = curl_init();
// Set target URL
curl_setopt($curl, CURLOPT_URL, "https://api.pingdom.com/api/2.0/checks");
// Set the desired HTTP method (GET is default, see the documentation for each request)
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
// Set user (email) and password
curl_setopt($curl, CURLOPT_USERPWD, "johndoe@example.com:password");
// Add a http header containing the application key (see the Authentication section of this document)
curl_setopt($curl, CURLOPT_HTTPHEADER, array("App-Key: zoent8w9cbt810rsdkweir23vcxb87zrt5541"));
// Ask cURL to return the result as a string
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Execute the request and decode the json result into an associative array
$response = json_decode(curl_exec($curl),true);
// Check for errors returned by the API
if (isset($response['error'])) {
print "Error: " . $response['error']['errormessage'] . "\n";
exit;
}
// Fetch the list of checks from the response
$checksList = $response['checks'];
// Print the names and statuses of all checks in the list
foreach ($checksList as $check) {
print $check['name'] . " is " . $check['status'] . "\n";
}
?>
@leoken
Copy link
Author

leoken commented Oct 12, 2012

This is taken directly from the pingdom documentation: https://www.pingdom.com/services/api-documentation-rest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment