<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Real-time dashboard using Web API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/537857#M16598</link>
    <description>&lt;P&gt;I have same requirement. Did you find any solution?&lt;/P&gt;</description>
    <pubDate>Tue, 09 Oct 2018 21:29:50 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-10-09T21:29:50Z</dc:date>
    <item>
      <title>Real-time dashboard using Web API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/389088#M11568</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;&lt;BR /&gt;Recently, I've struggling with &lt;STRONG&gt;real-time dashboards using API&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What I want&lt;/STRONG&gt;: to push data (which changes frequently) into datasets. Create dashboards where that data is updated automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenario:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is open web api about bitcoins:&lt;A href="https://api.cryptonator.com/api/ticker/btc-usd" target="_self"&gt; https://api.cryptonator.com/api/ticker/btc-usd &lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I want that data which is displayed in that api to be display in a dashboard, so that it is always showing the newest data. Is it possible to achieve that somehow?&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;U&gt;What I did:&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;1. GET &lt;A href="https://api.cryptonator.com/api/ticker/btc-usd" target="_self"&gt;https://api.cryptonator.com/api/ticker/btc-usd &lt;/A&gt;&lt;/P&gt;&lt;P&gt;2. POST &lt;A href="https://api.powerbi.com/v1.0/myorg/" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/&lt;/A&gt;............&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;C# Console application&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've already went through authorization - it is all good. I've also posted the data into power bi dataset, however, it is static and there is no current data displayed. Only the data once I get it from with GET.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to make it work if it is possible? Or how to achieve real-time dashboards?&lt;BR /&gt;&lt;BR /&gt;Btw, I've used google a lot, yet did not find a sample code (C# or smth) to achieve that. I would really appreaciate an assistant!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;

namespace walkthrough_push_data
{
    class Program
    {
        private static string token = string.Empty;

        static void Main(string[] args)
        {
            token = GetToken();

            CreateDataset();                  
            string datasetId = GetDataset();&lt;BR /&gt;
            AddRows(datasetId, "Bitcoin");
        }

        #region Get an authentication access token
        private static string GetToken()
        {
            string clientID = "******************";
            string redirectUri = "https://login.live.com/oauth20_desktop.srf";
            string resourceUri = "https://analysis.windows.net/powerbi/api";
            string authorityUri = "https://login.windows.net/common/oauth2/authorize";
            AuthenticationContext authContext = new AuthenticationContext(authorityUri);
            string token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken;

            Console.WriteLine(token);
            Console.ReadLine();

            return token;
        }
        #endregion

        #region Create a dataset in Power BI
        private static void CreateDataset()
        {
            string powerBIDatasetsApiUrl = "https://api.powerbi.com/v1.0/myorg/datasets?defaultRetentionPolicy=basicFIFO";

            HttpWebRequest request = WebRequest.Create(powerBIDatasetsApiUrl) as HttpWebRequest;
            request.KeepAlive = true;
            request.Method = "POST";
            request.ContentLength = 0;
            request.ContentType = "application/json";

            //Add token to the request header
            request.Headers.Add("Authorization", String.Format("Bearer {0}", token));

            //Create dataset JSON for POST request
            string datasetJson = "{\"name\": \"Test2\", \"tables\": " +
                "[{\"name\": \"Bitcoin\", \"columns\": " +
                "[{ \"name\": \"base\", \"dataType\": \"string\"}, " +
                "{ \"name\": \"target\", \"dataType\": \"string\"}, " +
                "{ \"name\": \"price\", \"dataType\": \"string\"}," +
                "{ \"name\": \"volume\", \"dataType\": \"string\"}," +
                "{ \"name\": \"change\", \"dataType\": \"string\"}" +
                "]}]}";

            //POST web request
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(datasetJson);
            request.ContentLength = byteArray.Length;
            using (Stream writer = request.GetRequestStream())
            {
                writer.Write(byteArray, 0, byteArray.Length);
                var response = (HttpWebResponse)request.GetResponse();
                Console.WriteLine(string.Format("Dataset {0}", response.StatusCode.ToString()));
                Console.ReadLine();
            }
        }
        #endregion

        #region Get a dataset to add rows into a Power BI table
        private static string GetDataset()
        {
            string powerBIDatasetsApiUrl = "https://api.powerbi.com/v1.0/myorg/datasets";
            HttpWebRequest request = WebRequest.Create(powerBIDatasetsApiUrl) as HttpWebRequest;
            request.KeepAlive = true;
            request.Method = "GET";
            request.ContentLength = 0;
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", String.Format("Bearer {0}", token));

            string datasetId = string.Empty;

            using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse)
            {
                using (StreamReader reader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    string responseContent = reader.ReadToEnd();
                    var results = JsonConvert.DeserializeObject&amp;lt;dynamic&amp;gt;(responseContent);
                    datasetId = results["value"][0]["id"];&lt;BR /&gt;
                    Console.WriteLine(String.Format("Dataset ID: {0}", datasetId));
                    Console.ReadLine();

                    return datasetId;
                }
            }
        }
        #endregion

        #region Add rows to a Power BI table
        private static string AddRows(string datasetId, string tableName)
        {
            string powerBIApiAddRowsUrl = String.Format("https://api.powerbi.com/v1.0/myorg/datasets/{0}/tables/{1}/rows", "**********************", tableName);&lt;BR /&gt;
            HttpWebRequest request = WebRequest.Create(powerBIApiAddRowsUrl) as HttpWebRequest;
            request.KeepAlive = true;
            request.Method = "POST";
            request.ContentLength = 0;
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", String.Format("Bearer {0}", token));

            string rowsJson = "{\"rows\":" + "[" + GetJson() + "]}";

            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(rowsJson);
            request.ContentLength = byteArray.Length;

            using (Stream writer = request.GetRequestStream())
            {
                writer.Write(byteArray, 0, byteArray.Length);
                var response = (HttpWebResponse)request.GetResponse();&lt;BR /&gt;
                Console.WriteLine("Rows Added");
                Console.ReadLine();

                return response.ToString();
            }
        }
        #endregion

        private static string GetJson()
        {
            string url = "https://api.cryptonator.com/api/ticker/btc-usd"; // url pabandymui
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.KeepAlive = true;
            request.Method = "GET";
            request.Accept = "application/json";

            using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse)
            {
                using (StreamReader reader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    string responseContent = reader.ReadToEnd();

                    var results = JsonConvert.DeserializeObject&amp;lt;dynamic&amp;gt;(responseContent);
                    var json = JsonConvert.SerializeObject(results.ticker);

                    return json;
                }
            }
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 23:15:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/389088#M11568</guid>
      <dc:creator>bi-developer</dc:creator>
      <dc:date>2018-04-03T23:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Real-time dashboard using Web API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/392048#M11638</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you mean the real-time streaming in Power BI, then please check:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/service-real-time-streaming" target="_self"&gt;Real-time streaming in Power BI&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 06:20:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/392048#M11638</guid>
      <dc:creator>v-micsh-msft</dc:creator>
      <dc:date>2018-04-09T06:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Real-time dashboard using Web API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/392290#M11656</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you:)&lt;BR /&gt;&lt;BR /&gt;Our aim is to create real-time streaming with push dataset. The the question is: how?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 10:42:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/392290#M11656</guid>
      <dc:creator>bi-developer</dc:creator>
      <dc:date>2018-04-09T10:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Real-time dashboard using Web API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/537857#M16598</link>
      <description>&lt;P&gt;I have same requirement. Did you find any solution?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 21:29:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/537857#M16598</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-09T21:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Real-time dashboard using Web API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/537871#M16600</link>
      <description>&lt;P&gt;You cannot create a real-time dashboard by&amp;nbsp;making a single call into the Power BI Service API to create rows. Instead, you must call into the Power BI Service API any time the underlying data changes. This means you&amp;nbsp;must find a way to periodcally trigger the code that retrieves the latest data and updates the dataset in Power BI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, you could create an Azure function with a schedule that executes once a minute. When this Azure function executes, it would call to the bitcoins API to get the latest data and then call to the&amp;nbsp;Power BI Service API to push the changes into your dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's easier to create a realt-time dashboard if the API you are using to get the data provides some callback mechanism such as a webhook. If yoy can register a webhook, you don't have to&amp;nbsp;periodically poll the API to detect changes because the webhook callback can trigger the code which gets the latest values and updates the real-time dataset in Power BI.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 21:53:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Real-time-dashboard-using-Web-API/m-p/537871#M16600</guid>
      <dc:creator>TedPattison</dc:creator>
      <dc:date>2018-10-09T21:53:12Z</dc:date>
    </item>
  </channel>
</rss>

