Introduction
This article contains some basic examples of how to call the VETtrak API web services from PHP, using PHP's standard SOAP library. These examples require the "soap" extension to be enabled in PHP.
Simple example
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient('http://apiserver.domain.com.au/VETtrakAPI/VT_API.asmx?WSDL', $options);
$clie_info = array('sUsername' => 'vettrak', 'sPassword' => 'trakker');
$result = $client->ValidateUser($clie_info);
print_r($result);
Slightly more advanced example
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient('http://apiserver.domain.com.au/VETtrakAPI/VT_API.asmx?WSDL', $options);
$loginInfo = array('sUsername' => 'vettrak', 'sPassword' => 'trakker');
$result = $client->ValidateUser($loginInfo);
if($result->ValidateUserResult->Status != 1)
{
// Failure - error message is in $result->ValidateUserResult->StatusMessage
die('Failure calling ValidateUser: ' . $result->ValidateUserResult->StatusMessage);
}
$token = $result->ValidateUserResult->Token;
$result = $client->GetWebOccurrences(array('sToken' => $token));
if($result->GetWebOccurrencesResult->Auth->Status != 1)
{
// Failure - error message is in $result->GetWebOccurrencesResult->Auth->StatusMessage
die('Failure calling GetWebOccurrences: ' . $result->GetWebOccurrencesResult->Auth->StatusMessage);
}
foreach($result->GetWebOccurrencesResult->OccuList->TOccu as $occurrence)
{
echo $occurrence->Prog_Name . ' running from ' . $occurrence->StartDate . ' to ' . $occurrence->EndDate . "<br/>\n";
}