Check your Windows Azure Datamarket remaining quota

In my previous post, I show you how to use Windows Azure Datamarket to create a Bing Search Engine Position checker. I told you that for free account, you only have 5000 requests per month. Paid subscription has higher limit.
This time I’ll show you how to check your remaining monthly quota for all of your Windows Azure Datamarket subscription without logging in to Azure Datamarket. This is the main function:

error_reporting(E_ALL^E_NOTICE);

function check_bing_quota($key) {
	$ret=array();
	
	$context = stream_context_create(array(
		'http' => array(
		    'request_fulluri' => true,
		    'header'  => "Authorization: Basic " . base64_encode($key . ":" . $key)
			)
		)
	);
	
	$end_point='https://api.datamarket.azure.com/Services/My/Datasets?$format=json';
	
	$response=file_get_contents($end_point, 0, $context);
		
	$json_data=json_decode($response);
	
	foreach ($json_data->d->results as $res) {
		$ret[]=array(
			'title'=>$res->Title,
			'provider'=>$res->ProviderName,
			'entry_point'=>$res->ServiceEntryPointUrl,
			'remaining'=>$res->ResourceBalance
		);
	}
	
	return $ret;
}

How to call it:

$ret=check_bing_quota('put_your_real_account_key_here');

Example result:

array(2) {
  [0]=>
  array(4) {
    ["title"]=>
    string(36) "Bing Search API รขโ‚ฌโ€œ Web Results Only"
    ["provider"]=>
    string(4) "Bing"
    ["entry_point"]=>
    string(57) "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb"
    ["remaining"]=>
    int(4981)
  }
  [1]=>
  array(4) {
    ["title"]=>
    string(15) "Bing Search API"
    ["provider"]=>
    string(4) "Bing"
    ["entry_point"]=>
    string(54) "https://api.datamarket.azure.com/Data.ashx/Bing/Search"
    ["remaining"]=>
    int(4997)
  }
}

Fully working demo: http://demo.ahowto.net/bing_quota/

check remaining quota in Windows Azure Datamarket

example output formatted as table

Notes:

  1. The function will check ALL of your Windows Azure Datamarket subscription
  2. checking your quota does not subtract your quota
  3. your PHP version must be at least 5.2 and PHP-openssl module must be activated
  1. Here’s a script to check your azure subscription’s credit remaining. Pipe it to another cmdlet to get creative ๐Ÿ™‚

    https://www.lineral.com/scripting-trick-to-get-microsoft-azure-credit-remaining/

  2. I have to say.. Awesome work..
    You just solved my problem.. thanks for this useful script

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackbacks and Pingbacks: