Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi Everyone,
I want to refresh mutliple datasets synchornously using Rest API in C#. 2nd dataset refresh should be called only after 1st dataset refresh gets completed, Challenge which i face right now is, even before 1st gets completed, 2nd gets called and its getting SQL time out issue because of overload.
1st dataset refresh takes minimum 30-45 mins and time might vary due to server load as well. Please suggest how to handle this!!
foreach (var res in comparedResult)
{
HttpWebRequest request = System.Net.HttpWebRequest.CreateHttp(String.Format("https://api.powerbi.com/v1.0/myorg/groups/{0}/datasets/{1}/refreshes", res.GroupId, res.DatasetId));
//POST web request to create a datasource.
request.KeepAlive = true;
request.Method = "POST";
request.ContentLength = 0;
//Add token to the request header
request.Headers.Add("Authorization", String.Format("Bearer {0}", token));
Console.WriteLine("Dataset refresh request started for Dataset Id {0}", res.DatasetId);
//Write JSON byte[] into a Stream
using (Stream writer = request.GetRequestStream())
{
var response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Dataset refresh request done for Dataset Id {0}", res.DatasetId);
}
}
Solved! Go to Solution.
Hi Ted,
Yeah you are almost right but we can use status column instead of start time / end time to identify whether API call got over or not. This is how I achieved it.
IRestResponse response = client.Execute(request);
var content = response.Content;
string statusName = string.Empty;
if (switchControl.ToLower() == "sync")
{
while (statusName.ToLower() != "completed")
{
statusName = GetRefreshHistoryByDatasetId(res.GroupId, res.DatasetId, token);
if (statusName.ToLower() != "completed")
{
Thread.Sleep(sleepTime * 60 * 1000); //In minutes
}
if (statusName.ToLower() == "failed")
{
break;
}
continue;
}
}
Can you please advise how you generated the token
Can you please list out the steps that you have performed for this activity
Like Application Registartion , Permissions granted ..Admin Consent required or not ..etc
Any reply please?
I got the solution, Let me know if anyone facing the same issue, I can help.
How did you solve this? I assumed you probably are using the REST API to retreive the refresh history which shows the state time and end time of each refresh history item. At first, a refresh history item will have a start time but no end time indiacting it is still in progress. Then you must poll the in-progress refresh history item to see when an end time is posted and you can begin the second refresh.
Is this how you accomplished your goal?
Hi Ted,
Yeah you are almost right but we can use status column instead of start time / end time to identify whether API call got over or not. This is how I achieved it.
IRestResponse response = client.Execute(request);
var content = response.Content;
string statusName = string.Empty;
if (switchControl.ToLower() == "sync")
{
while (statusName.ToLower() != "completed")
{
statusName = GetRefreshHistoryByDatasetId(res.GroupId, res.DatasetId, token);
if (statusName.ToLower() != "completed")
{
Thread.Sleep(sleepTime * 60 * 1000); //In minutes
}
if (statusName.ToLower() == "failed")
{
break;
}
continue;
}
}
How to run c# or curl command in PowerBI?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
13 | |
2 | |
2 | |
1 | |
1 |