Created
December 29, 2022 11:32
-
-
Save ChobPT/2f42cb15dcc30741e5d66c18d0e5b96a to your computer and use it in GitHub Desktop.
Bulk Add domains to Uptime Robot's Free Plan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This will add a bulk amount of domains to Uptimee Robot, | |
did this due to having a massive new amount of clients | |
and wanting to streamline the pricess | |
The function was built with the help of AI, I've corrected some stuff and added some workarounds for time limits and etc. | |
Tested to be working, needed a couple of runs to prevent duplicate domains from being added again | |
Hope it helps | |
*/ | |
$apiKey = "your-uptime-api-key"; | |
$urls = array( | |
"http://example.com", | |
"http://example.net" | |
); | |
// this is used to prevent the script from timing out, but not tested | |
set_time_limit(count($urls)*10); | |
ini_set('max_execution_time', count($urls)*10); | |
function addDomainsToUptime($apiKey, $urls) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://api.uptimerobot.com/v2/newMonitor"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$headers = array(); | |
$headers[] = "Content-Type: application/x-www-form-urlencoded"; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$results = array(); | |
foreach ($urls as $url) { | |
curl_setopt($ch, CURLOPT_POSTFIELDS, "api_key=$apiKey&type=1&url=$url&friendly_name=".str_replace('http://','',$url)); | |
$result = curl_exec($ch); | |
if (curl_errno($ch)) { | |
echo 'Error:' . curl_error($ch); | |
} | |
$results[] = $result; | |
// There's a 10 request per minute limit on the free plan, so we wait | |
sleep(10); | |
} | |
curl_close($ch); | |
return $results; | |
} | |
$responses = addDomainsToUptime($apiKey, $urls); | |
foreach ($responses as $response) { | |
echo "<br> ".$response; | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pro tip: Test this with one domain to make sure it's doing what you want before you fill the array with 10s of entries :)