Display online users (merchants, affiliates) via API

The following script publishes the merchants, affiliates being logged in.
// PapApi.class.php can be downloaded from the merchant panel at:
// Tools > Integration > API Integration > Download PAP API
// This include assumes the PapApi.class.php file is in the same directory as this particular script
include 'api/PapApi.class.php';

// login (as merchant)
$session = new Pap_Api_Session("https://localhost/pap/scripts/server.php"); 

//change it for your merchant panel login credentials here
if(!$session->login("merchant@username.com", "password")) { 
  die("Cannot login. Message: ".$session->getMessage());

// initiate a new grid request
$request = new Gpf_Rpc_Gridrequest("Gpf_Report_OnlineUsers", "getRows", $session);

//$request->addFilter('roleid', 'E', 'pap_aff'); //use this filter if you want to load only affiliates
//$request->addFilter('roleid', 'NE', 'pap_aff'); //use this filter if you want to load all merchant's roles

// send request
try {
} catch(Exception $e) {
  die("API call error: ".$e->getMessage());

// request was successful, get the grid result
$grid = $request->getGrid();

// get recordset from the grid
$recordset = $grid->getRecordset();

foreach($recordset as $rec) {
    echo 'Name: '.$rec->get('firstname').' '.$rec->get('lastname').' Username: '.$rec->get('username').' IP: '.$rec->get('ip').'<br>';