Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I'm trying to figure out how push data into datasets through PowerBI API. Because of it I tried to execute example Push data into a Power BI dataset and at Step 5: Add rows to a Power BI table I got an error on this line:
var response = (HttpWebResponse)request.GetResponse();
Text of error:
Unhandled Exception: System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at PushDataApp.Program.AddRows(String datasetId, String tableName) in c:\users\oleg\documents\visual studio 2017\Projects\PushDataApp\PushDataApp\Program.cs:line 174 at PushDataApp.Program.Main(String[] args) in c:\users\oleg\documents\visual studio 2017\Projects\PushDataApp\PushDataApp\Program.cs:line 31
Why is this happening?
And one more thing. In this example at Step 2: Get an authentication access token on next line:
string token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken;
opens window where you need to enter email and password. Is there any way not to show this window and enter email/password in or through the program? I mean I (and users of my future program too) don't want to enter this data manually.
I'll appreciate any help.
@Zirochka wrote:
Hi,
I'm trying to figure out how push data into datasets through PowerBI API. Because of it I tried to execute example Push data into a Power BI dataset and at Step 5: Add rows to a Power BI table I got an error on this line:
var response = (HttpWebResponse)request.GetResponse();Text of error:
Unhandled Exception: System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at PushDataApp.Program.AddRows(String datasetId, String tableName) in c:\users\oleg\documents\visual studio 2017\Projects\PushDataApp\PushDataApp\Program.cs:line 174 at PushDataApp.Program.Main(String[] args) in c:\users\oleg\documents\visual studio 2017\Projects\PushDataApp\PushDataApp\Program.cs:line 31Why is this happening?
And one more thing. In this example at Step 2: Get an authentication access token on next line:
string token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken;opens window where you need to enter email and password. Is there any way not to show this window and enter email/password in or through the program? I mean I (and users of my future program too) don't want to enter this data manually.
I'll appreciate any help.
The 404 error indicates that probably you're not pushing data to the correct dataset. Note that only the datasets created via REST API can push data to. I'd doubt that in your case the getdataset() doesn't return expected datasetid, check my reply in this thread. Just try to change some code in the getdataset() function.
//Get the first id //datasetId = results["value"][0]["id"]; var datasets = results["value"]; foreach (var ds in datasets) { //return the id of the first salesmarketing dataset if (ds["name"] == "SalesMarketing") { datasetId = ds["id"]; break; } }
As to your second question, yes, it is possible. Check the approach and concern in Getting around Oauth2. People want to access the reports in Power BI Service shall have their own accounts.
"As to your second question, yes, it is possible. Check the approach and concern in Getting around Oauth2."
I wrote as you suggested in your answer. Here is my code:
string requestURL = "https://login.windows.net/common/oauth2/token"; HttpWebRequest request = System.Net.WebRequest.Create(requestURL) as System.Net.HttpWebRequest; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Headers.Add("Cache-Control", "no-cache"); string postData = "client_secret=zmZ%2BC1nx3SXgrBzVOce%2BPb4T6uxrpnmmDPHahzPUhE4%3D&client_id=" + clientID + "&grant_type=password&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi&username=MYUSERNAME%40microsoft.com&password=MYPASSWORD"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); Stream data = response.GetResponseStream(); response.Close();
and i get the error:
Unhandled Exception: System.Net.WebException: The remote server returned an erro r: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at PushDataApp.Program.GetToken() in C:\Users\Oleg\Documents\Visual Studio 20 17\Projects\PushDataApp\PushDataApp\Program.cs:line 90 at PushDataApp.Program.Main(String[] args) in C:\Users\Oleg\Documents\Visual Studio 2017\Projects\PushDataApp\PushDataApp\Program.cs:line 24
Line 90 is here:
WebResponse response = request.GetResponse();
Please, help me figure out how to do it.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
6 | |
6 | |
3 | |
2 | |
2 |