cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerbi_jenhen
Resolver I
Resolver I

Wait for Power BI dataset to refresh using the API

Hi,

 

Via Powershell I'm able to invoke the Power BI API to start a dataset refresh using the "refresh dataset in group" API but using a while loop like below on the status value doesn't appear to exit the loop when the refresh completes to a status "Completed"? How can I write logic to wait for the dataset refresh to complete as once completed I need to set a variable value to output for another process to trigger:

 

while($status -eq "Unknown")
{
Start-Sleep -s 5
$history = Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json
#this loop never exits even although the dataset refresh completes with status "Completed"
}
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You forgot to set the value of $status inside the loop.

Don't ask for it every five seconds. Every minute is enough.

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

You forgot to set the value of $status inside the loop.

Don't ask for it every five seconds. Every minute is enough.

You were correct in the end, thanks!

 

I needed to get the status from the $history.status within the while loop, I was getting this from the status variable outside of the while loop so this was never changing. After setting the while loop condition status to the while loop status the correct status value was returning to exit the while loop...phew! 

Thanks for your reply.

 

The value of status will be set by the Power BI Service, I'm using the Start-Sleep to wait for status to change to "Completed" when the refresh completes. However, once I see the refresh has completed the new status isn't reflected to exit the loop.

 

Thanks.

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.