REST .NET Example 3: Getting a list of tables for a profile and the supported dimensions/metrics
(Return to main article: Samples for .NET (REST) v1)
1. Specify Service URL:
private const string serviceURL = "http://SERVER_NAME:URCHIN_PORT/services/v1/reportservice/tables/";
2. Provide login and profile information:
private const string login = "YOUR_LOGIN"; private const string password = "YOUR_PASSWORD"; private const int profileId = PROFILE_ID;
3. Compose REST URL:
string url = serviceURL + "?login=" + login + "&password=" + password + "&profileId=" + profileId;
4. Retrieve account list:
XPathDocument xPathDocument = new XPathDocument(url);
5. Parsing response:
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator(); XmlNameTable xmlNameTable = new NameTable(); XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlNameTable); xmlNamespaceManager.AddNamespace("tns", "https://urchin.com/api/urchin/v1/"); XPathNodeIterator tableXPathNodeIterator = xPathNavigator.Select("/tns:getTableListResponse/table", xmlNamespaceManager);
6. Display the information about retrieved profiles:
while (tableXPathNodeIterator.MoveNext()) DisplayTable(tableXPathNodeIterator.Current); ..... // Function to display storage info. private static void DisplayTable(XPathNavigator tableXPathNavigator) { Console.WriteLine("Table id is \"" + tableXPathNavigator.SelectSingleNode("tableId/text()") + "\", "); // Display the table dimensions. Console.WriteLine("dimensions are:"); XPathNodeIterator dimensionsXPathNodeIterator = tableXPathNavigator.Select("dimensions/dimension/text()"); while (dimensionsXPathNodeIterator.MoveNext()) Console.WriteLine("\t\"" + dimensionsXPathNodeIterator.Current.Value + "\", "); // Display the table metrics. Console.WriteLine("metrics are:"); XPathNodeIterator metricsXPathNodeIterator = tableXPathNavigator.Select("metrics/metric/text()"); while (metricsXPathNodeIterator.MoveNext()) Console.WriteLine("\t\"" + metricsXPathNodeIterator.Current.Value + "\", "); }
The full sample code for this example is available in ReportServiceGetStorageListREST.cs file.