Getting the Data Market Account Key
To access and consume any of the Data Market Datasets, you need to find your Account Key which will be used as a form of credentials.
- Go to http://datamarket.azure.com/account/info.
- Log in with your Windows Live ID and click on My Account.
- At the Account Details page, click on Account Keys.

- If you have not consumed datasets from Windows Azure Data Market before, your first account key will be found under the Default label as shown:

Subscribing to the a Dataset, eg Places.sg
Developers need to be subscribed to the dataset in order to use the data available. This example shows you how to subscribe to one of the datasets, Places.sg.
- Go to https://datamarket.azure.com/ and select Points of Interests.

- Select Places of Interests in Singapore.

- Click on Sign Up.

- Log into Windows Azure Marketplace Data Market using your Windows Live ID.
- Access the Places.sg API Terms of Use, check I have read and agree to the terms of use and Sign Up.

- Once you have successfully signed up, you will see the following Purchase Receipt.

- You have successfully subscribed to the Places.sg dataset and can access it from the My Data menu option.
Consuming the Places.sg Dataset
- Under the Places of Interests in Singapore dataset page you will find the Service Root URL to access the dataset from your application.

- Click on Explore this Dataset on the same page to test requests and see the content of the dataset.

Code Snippet — How do I access the Places.sg dataset
C#.NET
private List GetPlacesFromDataMarket(string UniqueUserId, string AccountKey)
{
WebRequest request = HttpWebRequest.Create(
"https://api.datamarket.azure.com/Data.ashx/PlacesSg/PlacesofInterestinSingapore/Places?$top =100");
request.Credentials = new NetworkCredential(UniqueUserId, AccountKey);
WebResponse response = request.GetResponse();
string strResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
XNamespace atomNS = "http://www.w3.org/2005/Atom";
XNamespace dNS = "http://schemas.microsoft.com/ado/2007/08/dataservices";
XNamespace mNS = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
List results = (from item in XElement.Parse(strResponse).Descendants(atomNS + "entry")
let place = item.Element(atomNS + "content").Element(mNS + "properties")
select new Places()
{
CompanyName = place.Element(dNS + "company_name").Value,
CompanyType = place.Element(dNS + "company_type").Value,
Category = place.Element(dNS + "category").Value
}).ToList();
return results;
}
class Places
{
public string CompanyName { get; set; }
public string CompanyType { get; set; }
public string Category { get; set; }
}
Java
private static ArrayList
getPlaces(String UniqueUserId, String AccountKey) {
// Declare an ArrayList for storing the data to be retrieved from Data Market
ArrayList placeList = new ArrayList();
try {
// Declare a URL object with the url of the Data Market Dataset
URL _url = new URL("https://api.datamarket.azure.com/Data.ashx/PlacesSg/PlacesofInterestinSingapore/Places?$top=100");
// Declare a URLConnection object and open a connection using the URL object declared previously
URLConnection _urlConn = _url.openConnection();
// Encode credential to base64 for HTTP Basic Access Authentication used by Data Market
BASE64Encoder encoder = new BASE64Encoder();
String credential = UniqueUserId + ":" + AccountKey;
String credentialBase64 = (encoder.encode(credential.getBytes())).replaceAll("\\s", "");
// Append the necessary Data Market authentication infomation to the URLConnection object
_urlConn.setRequestProperty("accept", "*/*");
_urlConn.addRequestProperty("Authorization", "Basic " + credentialBase64);
// BufferedReader object stores the response (InputStream) of the URLConnection object
BufferedReader br = new BufferedReader(new InputStreamReader(_urlConn.getInputStream()));
String line = null;
StringBuilder strBuilder = new StringBuilder();
while ((line = br.readLine()) != null) {
strBuilder.append(line);
}
// An array of String is used to store the data retrieved from Data Market and extracted later
String[] IProperties = strBuilder.toString().split("<m:properties>");
for (int i = 1; i < IProperties.length; i++) {
Place place = new Place();
// For each line of data, the function GetStringBetween extracts the content between the opening and closing xml tags
place.setCompanyName(GetStringBetween(
IProperties[i], "<d:company_name>", "</d:company_name>"));
place.setCompanyType(GetStringBetween(
IProperties[i], "<d:company_type>", "</d:company_type>"));
place.setCategory(GetStringBetween(
IProperties[i], "<d:category>", "</d:category>"));
placeList.add(place);
}
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return placeList;
}
private static String GetStringBetween(String src, String start, String end) {
StringBuilder sb = new StringBuilder();
int startIdx = src.indexOf(start) + start.length();
int endIdx = src.indexOf(end);
while (startIdx < endIdx) {
sb.append(String.valueOf(src.charAt(startIdx)));
startIdx++;
}
return sb.toString();
}
static class Place {
private String companyName;
private String companyType;
private String category;
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getCompanyType() {
return companyType;
}
public void setCompanyType(String companyType) {
this.companyType = companyType;
}
php
<http>
<head>
<title>Get Places of Interests in Singapore</title>
</head>
<body>
<?php
$UniqueUserId = '';
$AccountKey = '';
$url ='https://api.datamarket.azure.com/Data.ashx/PlacesSg/PlacesofInterestinSingapore/Places?$top=100';
$params = array(
'http' => array(
'method' => 'GET',
'header' => 'Authorization: Basic '.base64_encode($UniqueUserId.':'.$AccountKey)
)
);
$context = stream_context_create($params);
$page = file_get_contents($url, false, $context);
$doc = new DOMDocument();
$doc->loadXML($page);
?>
<table border="1">
<tr>
<th>Company Name</th>
<th>Company Type&</th>
<th>Category</th>
</tr>
<?php
foreach ($doc->getElementsByTagName('properties') as $node) {
echo '<tr>'."\n";
echo '<td>'.$node->getElementsByTagName('company_name')->item(0)->nodeValue.'</td>'."\n";
echo '<td>'.$node->getElementsByTagName('company_type')->item(0)->nodeValue.'</td>'."\n";
echo '<td>'.$node->getElementsByTagName('category')->item(0)->nodeValue.'</td>'."\n";
echo '</tr>'."\n";
}
?>
</table>