In this post we’ll take you through how to list tests from your account, and their detailed settings through the API. There are two functions involved here, first is the function that lists ALL tests on the account with important settings, and second is a more detailed call for a single test. As usual we’ll take you through this process for both of these using PHP, bash, Python and Postman.

PHP Example 1 – Get all tests

<?php
// Auth the request
$API = “l6OxVJilcD2cETMoNRvn”;
$Username = “StatusCake”;
// Create the CURL
$ch = curl_init(“https://app.statuscake.com/API/Tests/”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
“API: “.$API,
“Username: “.$Username
));
// For Debugging
$Response = curl_exec($ch);
$Response = json_decode($Response);
// Check for success
if (!empty($Response->Success) && $Response->Success == 1) {
echo ‘Here’s the detailed data!’;
echo $Response;
echo ‘Here’s the data!’;
echo $Response;
} else {
echo ‘Something Went Wrong Grabbing the Data<BR>’;
echo $Response->Message;
}
?>

PHP Example 2 – Get detailed data on a single test

<?php
// Auth the request
$API = “l6OxVJilcD2cETMoNRvn”;
$Username = “StatusCake”;
$TestID = TESTIDHERE;
// Create the CURL
$ch = curl_init(“https://app.statuscake.com/API/Tests/Details/?TestID=” . $TestID);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
“API: “.$API,
“Username: “.$Username
));
// For Debugging
$Response = curl_exec($ch);
$Response = json_decode($Response);
// Check for success
if (!empty($Response->Success) && $Response->Success == 1) {
echo ‘Here’s the detailed data!’;
echo $Response;
} else {
echo ‘Something Went Wrong Grabbing the details<BR>’;
echo $Response->Message;
}
?>

Bash Example 1 – Get all tests

curl -H “API: [APIKey]” -H “Username: [Username]” -X GET https://app.statuscake.com/API/Tests/Details/?TestID=TESTIDHERE

Bash Example 2 – Get all tests

curl H “API: [APIKey]” H “Username: [Username]” X GET https://app.statuscake.com/API/Tests/

Python Example 1 – Get all tests

# -*- coding: utf-8 -*-
import requests
headers = {‘API’: ‘APIKEYHERE’,’Username’: ‘USERNAMEHERE’}
url = ‘https://app.statuscake.com/API/Tests/’
r = requests.post(url, headers=headers)
print(r.text)

Python Example 2 – Get detailed data on a single test

# -*- coding: utf-8 -*-
import requests
headers = {‘API’: ‘APIKEYHERE’,’Username’: ‘USERNAMEHERE’}
url = ‘https://app.statuscake.com/API/Tests/Details/?TestID=TESTIDHERE’
r = requests.post(url, headers=headers)
print(r.text) 

Postman Example 1 – Get all tests

pmALL

Postman Example 2 – Get detailed data on a single test

PMalltests

Comments are closed.