logo logo

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
bottom

No Responses to “Check your Windows Azure Datamarket remaining quota”

Trackbacks/Pingbacks

  1. Windows Azure and Cloud Computing Posts for 7/30/2012+ - Windows Azure Blog - [...] Zaenuri described how to Check your Windows Azure Datamarket remaining quota in a 7/25/2012 post to his How To …

Leave a Reply

Your email address will not be published. Required fields are marked *

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

bottom