Reputation: 111
I am using PowerShell to refresh my powerbi.com datasets programmaticlly. This is all working fine. What would be helpful, however, is if there is a way to retrieve the refresh completion time data from Microsoft. I could list the process I'm using to kick off the refresh, but that is well documented and not pertinent to this question.
Since powerbi.com shows the dataset refresh completion time, it would stand to reason that I could grab that data, but I cannot find any documentation on this. Has anyone on here tried to grab this data (screenshot below)?
Upvotes: 0
Views: 2183
Reputation: 13440
Instead of POST method, which will trigger a refresh, i.e. this is the Refresh Dataset In Group API, change the method to GET to use Get Refresh History In Group API. This will return information about the refreshes of this dataset. So the PowerShell code could be something like this:
Import-Module MicrosoftPowerBIMgmt
$username = "my super strong password"
$password = "[email protected]" | ConvertTo-SecureString -asPlainText -Force
$groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$datasetId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential
$refreshes_response = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$groupId/datasets/$datasetId/refreshes" -Method Get
Disconnect-PowerBIServiceAccount
$refreshes_response_json = ConvertFrom-Json $refreshes_response
foreach ($refresh in $refreshes_response_json.value)
{
Write-Output "refreshType: $($refresh.refreshType), startTime: $($refresh.startTime), endTime: $($refresh.endTime), status: $($refresh.status)"
}
You can also limit the number of refreshes returned by providing a number in the URL:
GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/refreshes?$top={$top}
But if the last one is not successful, you may want to look at older events to find the last successful one. Also look at the status of the refresh, because it may still be in progress (it will say Unknown
in such case).
Upvotes: 1