PHP code example to access the Wormly API

Be sure to substitute your API key and HostID(s).


<?php

$conn 
curl_init("https://api.wormly.com/");

$postdata["key"] = '__YOUR_KEY__';
$postdata["response"] = 'json';
$postdata["hostids"] = '__HOSTID1__,__HOSTID2__';
$postdata["cmd"] = "getHostStatus";

// Encode the POST data for use with CURL:
foreach ($postdata AS $key => $value)
{
    
$fields[] = rawurlencode($key)."=".rawurlencode($value);
}

curl_setopt($connCURLOPT_RETURNTRANSFER1);
curl_setopt($connCURLOPT_POSTtrue);
curl_setopt($connCURLOPT_ENCODING"gzip");
curl_setopt($connCURLOPT_POSTFIELDSjoin("&"$fields));

// Perform the API request
$response curl_exec($conn);

// Fetch the HTTP response code so we can verify it
$info curl_getinfo($conn);
$httpResponseCode $info['http_code'];

// Decode our JSON response object
$responseObject json_decode($response);

if (
$httpResponseCode == 200)
{
    
// The API request was successful    
    
$hostid =       $responseObject->status[0]->hostid;
    
$isHostDown =   $responseObject->status[0]->uptimeerrors;
}
else
{
    
// An error occurred
    
$wormlyErrorCode $responseObject->errorcode;
    
$wormlyErrorMessage $responseObject->errormsg;
}






Not what you were looking for? Try a search:

Ninja Tip: trace* will match traceroute.