Inbound: get list of inbound faxes using GetList

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 a list of inbound (received) faxes.

The sample uses method GetList.


<?php

/**************** Settings begin **************/

$username  = ''; // Enter your Interfax username here
$password  = ''; // Enter your Interfax password here
$listtype  = 'NewMessages'; // Enter the type of list you wish to return 
$maxitems  = '10'; // Maximum number of inbound faxes to return in list

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

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

$params->Username  = $username;
$params->Password  = $password;
$params->LType     = $listtype;
$params->MaxItems  = $maxitems;

$result = $client->GetList($params);

//print_r($result);

if (!$result->GetListResult){ // WS call successful
    if (count($result->objMessageItem->MessageItem) > 0) { 
        // the returned list is not empty
        if (count($result->objMessageItem->MessageItem) == 1 ){ 
            // there is exactly one item in returned list
            foreach ($result->objMessageItem AS $inboundfax){
            echo 'Message ID: ' . $inboundfax->MessageID . ''; 
            echo 'Phone Number: ' . $inboundfax->PhoneNumber . '';
            echo 'Remote CSID: ' . $inboundfax->RemoteCSID . '';
            echo 'Message Status: ' . $inboundfax->MessageStatus . '';
            echo 'Pages: ' . $inboundfax->Pages . '';
            echo 'Message Size: ' . $inboundfax->MessageSize . '';
            echo 'Message Type: ' . $inboundfax->MessageType . '';
            echo 'Receive Time: ' . $inboundfax->ReceiveTime . '';
            echo 'Caller ID: ' . $inboundfax->CallerID . '';
            echo 'Message Recording Duration: ' . $inboundfax->MessageRecordingDuration . '';
            }
        } else { 
            // there are two or more items returned in the list
            foreach ($result->objMessageItem->MessageItem AS $inboundfax){
            echo 'Message ID: ' . $inboundfax->MessageID . ''; 
            echo 'Phone Number: ' . $inboundfax->PhoneNumber . '';
            echo 'Remote CSID: ' . $inboundfax->RemoteCSID . '';
            echo 'Message Status: ' . $inboundfax->MessageStatus . '';
            echo 'Pages: ' . $inboundfax->Pages . '';
            echo 'Message Size: ' . $inboundfax->MessageSize . '';
            echo 'Message Type: ' . $inboundfax->MessageType . '';
            echo 'Receive Time: ' . $inboundfax->ReceiveTime . '';
            echo 'CallerID: ' . $inboundfax->CallerID . '';
            echo 'Message Recording Duration: ' . $inboundfax->MessageRecordingDuration . '';;
            }
        }
    } else { 
        // the returned list is empty
        echo 'No inbound faxes in list';
}
} else { // Bad WS call
    echo 'WS call failed';
}
?>