Skip to content

Instantly share code, notes, and snippets.

@Pushkraj19
Created February 19, 2026 11:11
Show Gist options
  • Select an option

  • Save Pushkraj19/ae00b44bfa58f3b23b838ed875986388 to your computer and use it in GitHub Desktop.

Select an option

Save Pushkraj19/ae00b44bfa58f3b23b838ed875986388 to your computer and use it in GitHub Desktop.
<?php
// Your API Key
$api_key = '************'; # -> Your API key goes here
// Add your websites to this array
$websites = ["https://example.in", "https://example.com"];
// Add Uptime Monitor API Call
$api_call = 'https://api.hetrixtools.com/v2/'.$api_key.'/uptime/add/';
foreach ($websites as $website) {
// Attempt to get the domain name from the URL for the monitor name
$domainName = parse_url($website, PHP_URL_HOST);
// If the domain name is empty, it might be an invalid URL, skip it
if (empty($domainName)) {
echo "Skipping invalid URL: {$website}\n";
continue;
}
// Common Variables
$common = [
'MID' => '', // Monitor ID to edit or delete. Needed when editing or deleting a monitor. Ignored when adding a monitor
'Type' => '1', // Monitor Type. Accepted: 1 - Website, 2 - Ping/Service, 3 - SMTP
'Name' => $domainName, // Monitor Name. Accepted: a-z, A-Z, 0-9, spaces, dots, dashes
'Target' => $website, // Link for Website Uptime Monitors, or IP/Hostname for all other Uptime Monitor types
'Timeout' => 10, // Timeout. Accepted: 3, 5, 10, [15 is available just for the website type]. Suggested: 10
'Frequency' => 1, // Checkup frequency (minutes). Accepted: 1, 3, 5, 10. Suggested: 1
'FailsBeforeAlert' => 3, // Failed tries before issuing alert. Accepted: 1-3. Suggested: 3
'Public' => false, // Privacy for this monitor's Uptime Report
'ShowTarget' => false, // Whether or not to show the monitored target in the uptime report
'VerSSLCert' => false, // Whether or not to verify the SSL certificate of the monitored target
'VerSSLHost' => false, // Whether or not to verify the SSL host of the monitored target
// Monitoring Locations
// Comment out (or set to false) the ones you do not wish to monitor from
// [min: 3, max: depends on your package(3,6,9,12)]
'Locations' => [
'nyc' => true, // New York
'sfo' => false, // San Francisco
'dal' => false, // Dallas
'ams' => false, // Amsterdam
'lon' => true, // London
'fra' => false, // Frankfurt
'sgp' => true, // Singapore
'syd' => false, // Sydney
'sao' => false, // Sao Paulo
'tok' => false, // Tokyo
'mba' => true, // Mumbai
'msw' => false, // Moscow
],
];
// Specific Monitor Type Variables
$specific[1] = [ // Website Uptime Monitor
'Method' => 'GET', // [Optional] Either GET or HEAD as the desired HTTP method used to access your website.
'Keyword' => '', // [Optional] Keyword to look for on the monitored website, leave empty for none. Max length: 128
'HTTPCodes' => '200', // [Optional] Specify the accepted HTTP codes (separated by comma). Your website will be considered online if any of these HTTP codes is returned.
'MaxRedirects' => '3', // Maximum number of redirects to follow. Accepted: 0-10
];
// Prepare JSON
$post = array_merge($common, $specific[$common['Type']]);
$post = json_encode($post);
// Make the API Call
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $api_call);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$data = curl_exec($ch);
curl_close($ch);
// Return the data
echo "API Response for {$website}: {$data}\n";
}
// Example returns
// {"status":"ERROR","error_message":"you are already monitoring this target"}
// {"status":"SUCCESS","monitor_id":"xyz","action":"added"}
// {"status":"SUCCESS","monitor_id":"xyz","action":"updated"}
// {"status":"SUCCESS","monitor_id":"xyz","action":"deleted"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment