So I have been working on being able to import pbix reports through my application and then being able to view them through it. I have this almost all teh way working right now. The only issue still outstanding is after I inport a report, the credentials on the dataset seem to get lost.
I have been trying to use etiher the C# API Wrapper, or the direct Rest API url's to do this, but so far to no avail. My current code will be below, but right now, everything works, and I do not get any errors. However, I do not get any success message back either, and after I update the connection string, the report still will not load in my application or in Power BI Itself. It continues to say it needs credentials.
If anyone can help me figure out whats wrong with the way I am currently doing this, or give me working code of another way, say using the C# Wrapper of the API, I would apprecaite it very much.
if (importResponse == "Accepted") { ODataResponseListDataset oRld = client.Datasets.GetDatasetsInGroup(GroupId); Dataset dataSet = oRld.Value.Where(x => x.Name == fileNameWithoutExtension).FirstOrDefault(); if(dataSet != null) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.powerbi.com/v1.0/myorg/groups/" + GroupId + "/datasets/" + dataSet.Id + "/Default.SetAllConnections"); request.Method = "POST"; request.KeepAlive = true; request.ContentType = "application/json"; request.Headers.Add("Authorization", String.Format("Bearer {0}", token.ToString())); using (System.IO.Stream s = request.GetRequestStream()) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(s)) { connectionObject conn = new connectionObject { connectionString = ConfigurationManager.AppSettings["pbiConnString"].ToString() }; string json = JsonConvert.SerializeObject(conn); sw.Write(json); } } using (System.IO.Stream s = request.GetResponse().GetResponseStream()) { using (System.IO.StreamReader sr = new System.IO.StreamReader(s)) { var jsonResponse = sr.ReadToEnd(); System.Diagnostics.Debug.WriteLine(String.Format("Response: {0}", jsonResponse)); } } repo.Create(new ReportsModel { CompanyId = user.CompanyID, DateUploaded = DateTime.Now, Name = fileNameWithoutExtension, URL = "" }); } }
Where the connectionString object looks like....
public struct connectionObject { public string connectionString { get; set; } }