Get information about one or more submitted faxes with FaxQuery2

25 Nov 2016 This code sample is deprecated and in process of being removed. Check out our new code libraries and usage documentation on InterFAX @ Github.

This sample demonstrates how to retrieve information about a sent fax using the FaxQuery2 method. This method has more flexible querying options than FaxQuery.


<?php

/**************** Settings begin **************/
// See http://www.interfax.net/en/dev/webservice/reference/faxquery2
// for an explanation of properties           

// Valid values for [property]_verb are:
// Equals | GreaterThan | GreaterOrEqual | LessThan | LessOrEqual | Like | IncludedIn | Between
// Leave both [property]_verb and [property]_data empty to ignore the property in the query

$username = '';  
$password = '';

$subject_verb = '';
$subject_data = '';

$faxnumber_verb = '';
$faxnumber_data = '';

$date_from = '';
$date_to = '';

$user_id_verb = '';
$user_id_data = '';

$reply_address_verb = '';
$reply_address_data = '';

$transaction_id_verb = '';
$transaction_id_data = '';

$parent_transaction_id_verb = '';
$parent_transaction_id_data = '';

$status_verb = '';
$status_data = '';

// The following values control display settings

$show_hidden_transactions = TRUE;
$only_parents = FALSE;
$num_of_results = 100;
$starting_record = 0;

// Valid values for $order_by are:
// TransactionID | SubmitTime | CompletionTime | Status | DestinationFax | Subject | PagesSent | UserID | ReplyEmail

$order_by = 'TransactionID';
$asc_order_direction = TRUE;
$return_items = TRUE;
$return_stats = TRUE;

/**************** Settings end **************/

// Set default values for empty query properties

if(!($subject_verb && $subject_data)){
    $subject_verb = 'Equals';
    $subject_data = '';
}

if(!($faxnumber_verb && $faxnumber_data)){
    $faxnumber_verb = 'Equals';
    $faxnumber_data = '';
}

if(!$date_from) $date_from = '1999-01-01T00:00:01';

if(!$date_to) $date_to = '2999-12-31T23:59:59';

if(!($user_id_verb && $user_id_data)){
    $user_id_verb = 'Equals';
    $user_id_data = '';
}

if(!($reply_address_verb && $reply_address_data)){
    $reply_address_verb = 'Equals';
    $reply_address_data = '';
}

if(!($transaction_id_verb && $transaction_id_data)){
    $transaction_id_verb = 'Equals';
    $transaction_id_data = '';
}

if(!($parent_transaction_id_verb && $parent_transaction_id_data)){
    $parent_transaction_id_verb = 'Equals';
    $parent_transaction_id_data = '';
}

if(!($status_verb && !is_null($status_data))){
    $status_verb = 'Equals';
    $status_data = '';
}

// End setting default values


$params->Username                                 = $username;
$params->Password                                 = $password;
$params->QueryForm->Subject->Verb                 = $subject_verb;
$params->QueryForm->Subject->VerbData             = $subject_data;
$params->QueryForm->FaxNumber->Verb               = $faxnumber_verb;
$params->QueryForm->FaxNumber->VerbData           = $faxnumber_data;
$params->QueryForm->DateFrom                      = $date_from;
$params->QueryForm->DateTo                        = $date_to;
$params->QueryForm->UserID->Verb                  = $user_id_verb;
$params->QueryForm->UserID->VerbData              = $user_id_data;
$params->QueryForm->ReplyAddress->Verb            = $reply_address_verb;
$params->QueryForm->ReplyAddress->VerbData        = $reply_address_data;
$params->QueryForm->TransactionID->Verb           = $transaction_id_verb;
$params->QueryForm->TransactionID->VerbData       = $transaction_id_data;
$params->QueryForm->ParentTransactionID->Verb     = $parent_transaction_id_verb;
$params->QueryForm->ParentTransactionID->VerbData = $parent_transaction_id_data;
$params->QueryForm->Status->Verb                  = $status_verb;
$params->QueryForm->Status->VerbData              = $status_data;
$params->QueryForm->ShowHiddenTransactions        = $show_hidden_transactions;
$params->QueryControl->OnlyParents                = $only_parents;
$params->QueryControl->NumOfResults               = $num_of_results;
$params->QueryControl->StartingRecord             = $starting_record;
$params->QueryControl->OrderBy                    = $order_by;
$params->QueryControl->AscOrderDirection          = $asc_order_direction;
$params->QueryControl->ReturnItems                = $return_items;
$params->QueryControl->ReturnStats                = $return_stats;


$client = new SoapClient("http://ws.interfax.net/dfs.asmx?wsdl");

// Use the call below to trace PHP's SOAP call
// $client = new SoapClient("http://ws.interfax.net/dfs.asmx?wsdl", array('trace' => 1));

$queryResult = $client->FaxQuery2($params);

// Display the SOAP call; use in conjunction with the alternative SOAP call above
// echo $client->__getLastRequest();

// Format and present retrieved data

if ($queryResult->FaxQuery2Result->ResultCode == 0){ // status request succeeded

    if ($return_stats){
        echo 'Stats';
        $statsCount = count($queryResult->FaxQuery2Result->Stats->StatusCount);

        switch($statsCount){
            case 0:
                echo 'No transactions fit query';
                break;
            
            case 1:
                echo 'Status ' . $queryResult->FaxQuery2Result->Stats->StatusCount->Status . ' :';
                echo $queryResult->FaxQuery2Result->Stats->StatusCount->Count . '';
                break;

            default:
                for($j = 0; $j < $statsCount; $j++){
                    echo 'Status ' . $queryResult->FaxQuery2Result->Stats->StatusCount[$j]->Status . ' :';
                    echo $queryResult->FaxQuery2Result->Stats->StatusCount[$j]->Count . '';
                }
                break;
        }
    }

    if ($return_items){ 

        $queryCount = count($queryResult->FaxQuery2Result->FaxItems->FaxItemEx2);
        echo 'Details';
        switch($queryCount){
            case 0:
                echo 'No transactions fit query';
                break;
     
            case 1: // single item returned by WS call
                echo 'ParentTransactionID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->ParentTransactionID . '';
                echo 'TransactionID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->TransactionID . '';
                echo 'SubmitTime: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->SubmitTime . '';
                echo 'PostponeTime: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->PostponeTime . '';
                echo 'CompletionTime: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->CompletionTime . '';
                echo 'UserID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->UserID . '';
                echo 'Contact: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->Contact . '';
                echo 'Job ID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->JobID . '';
                echo 'DestinationFax: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->DestinationFax . '';
                echo 'ReplyEmail: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->ReplyEmail . '';
                echo 'RemoteCSID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->RemoteCSID . '';
                echo 'PagesSent: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->PagesSent . '';
                echo 'Status: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->Status . '';
                echo 'Duration: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->Duration . '';
                echo 'Subject: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->Subject . '';
                echo 'PagesSubmitted: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->PagesSubmitted . '';
                echo 'SenderCSID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->SenderCSID . '';
                echo 'Priority: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->Priority . '';
                echo 'Units: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->Units . '';
                echo 'CostPerUnit: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->CostPerUnit . '';
                echo 'PageSize: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->PageSize . '';
                echo 'PageOrientation: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->PageOrientation . '';
                echo 'PageResolution: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->PageResolution . '';
                echo 'RenderingQuality: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->RenderingQuality . '';
                echo 'PageHeader: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->PageHeader . '';
                echo 'RetriesToPerform: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->RetriesToPerform . '';
                echo 'TrialsPerformed: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->TrialsPerformed . '';
                echo 'LocaleID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->LocaleID . '';
                echo 'GMTBias: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->GMTBias . '';
                echo 'RetriesInterval: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->RetriesInterval . '';
                echo 'UserData: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->UserData . '';
                echo 'DeleteAfterUsage: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->DeleteAfterUsage . '';
                echo 'Mode: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->Mode . '';
                echo 'NumOfTransactions: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->NumOfTransactions . '';
                echo 'MessageID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2->MessageID . '';
                break;
     
            default: // multiple items returned by WS call
                for($i = 0; $i < $queryCount; $i++){
                    echo 'ParentTransactionID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->ParentTransactionID . '';
                    echo 'TransactionID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->TransactionID . '';
                    echo 'SubmitTime: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->SubmitTime . '';
                    echo 'PostponeTime: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->PostponeTime . '';
                    echo 'CompletionTime: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->CompletionTime . '';
                    echo 'UserID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->UserID . '';
                    echo 'Contact: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->Contact . '';
                    echo 'Job ID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->JobID . '';
                    echo 'DestinationFax: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->DestinationFax . '';
                    echo 'ReplyEmail: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->ReplyEmail . '';
                    echo 'RemoteCSID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->RemoteCSID . '';
                    echo 'PagesSent: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->PagesSent . '';
                    echo 'Status: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->Status . '';
                    echo 'Duration: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->Duration . '';
                    echo 'Subject: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->Subject . '';
                    echo 'PagesSubmitted: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->PagesSubmitted . '';
                    echo 'SenderCSID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->SenderCSID . '';
                    echo 'Priority: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->Priority . '';
                    echo 'Units: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->Units . '';
                    echo 'CostPerUnit: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->CostPerUnit . '';
                    echo 'PageSize: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->PageSize . '';
                    echo 'PageOrientation: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->PageOrientation . '';
                    echo 'PageResolution: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->PageResolution . '';
                    echo 'RenderingQuality: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->RenderingQuality . '';
                    echo 'PageHeader: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->PageHeader . '';
                    echo 'RetriesToPerform: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->RetriesToPerform . '';
                    echo 'TrialsPerformed: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->TrialsPerformed . '';
                    echo 'LocaleID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->LocaleID . '';
                    echo 'GMTBias: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->GMTBias . '';
                    echo 'RetriesInterval: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->RetriesInterval . '';
                    echo 'UserData: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->UserData . '';
                    echo 'DeleteAfterUsage: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->DeleteAfterUsage . '';
                    echo 'Mode: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->Mode . '';
                    echo 'NumOfTransactions: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->NumOfTransactions . '';
                    echo 'MessageID: ' . $queryResult->FaxQuery2Result->FaxItems->FaxItemEx2[$i]->MessageID . '';
                    echo '------------------------------------';
                }  // close loop
                    break;
            }  // close switch
    }
} else { // problem getting status
    // Do something here, like alerting an administrator
    echo 'Problem retrieving status, error ' . $queryResult->FaxQuery2Result->ResultCode . '';
}

?>

Contact us today

Talk to a member of our team about the benefits InterFAX can bring to your organization's communications processes.

Contact us today