Get Data Usage For Cricket Wireless
 Page :   [ 1 ]    [ 2 ]  

Here is the script you would request in the browser.

 

<?php 

$username = 'yourUsername';
$password = 'yourPassword';

include 'Cricket.class.php';

$return = array();

$cricket = Cricket::getByLogin($username, $password);

if ($cricket){
	
	$subscribers = $cricket->getSubscribers();

	if ($subscribers){

		$return['billCycleDate'] = $cricket->getBillCycleDate();
		$return['nextBillDueDays'] = $cricket->getNextBillDueDays();
		
		foreach ($subscribers as $skey => $subscriber){
			
			if (isset($subscriber['usage'])){
		
				$usage = $subscriber['usage'];

				// not sure if this limitedServices is appropriate all the time
				// it is for my account
				if (isset($usage['limitedServices'])){
						
					$ls = $usage['limitedServices'];
					
					if (is_array($ls) && count($ls)){
		
						$use = $ls[0]; // dont know how appropriate this is
						// i.e. is there always just one element ? or sometimes more for
						// a dataplan that is somehow different ??
		
						$return['subscribers'][$skey]['totalAllowance'] = $use['totalAllowance'];
						$return['subscribers'][$skey]['consumedAllowance'] = $use['consumedAllowance'];
						$return['subscribers'][$skey]['remainingAllowance'] = $use['remainingAllowance'];
						$return['subscribers'][$skey]['uom'] = $use['uom'];
		
					}
						
				}
		
			}
		}
		
	}
	
}

header('Content-type: application/json');

echo json_encode($return);

die();

?>

 

Some sample JSON output.

 

{
	"billCycleDate": "02\/03\/2016 00:00:00",
	"nextBillDueDays": "2",
	"subscribers": {
		"2085555555": {
			"totalAllowance": "2560",
			"consumedAllowance": "537",
			"remainingAllowance": "2022",
			"uom": "MB"
		}
	}
}

 

(Page 2 of 2)