Sub topic 15
Triggering and inspecting refreshes with the REST API
This chapter assumes you have a published dataset with a working schedule, as set up in earlier chapters. It also assumes you can run PowerShell and have installed the MicrosoftPowerBIMgmt module. The account you sign in with needs write permission on the dataset.
Why use the API
The portal's Refresh now button and schedule cover most cases. The REST API helps when a refresh must start after something else finishes, such as an ETL job that loads your SQL Server tables. It also lets scripts read refresh history and change schedules without opening the portal.
An API refresh uses the same gateway and credentials as a scheduled one. It still fails if the gateway data source is not mapped.
Trigger a refresh
The POST call queues the refresh and returns at once. A 202 Accepted response means the request was queued, not that the refresh succeeded.
Connect-PowerBIServiceAccount
$groupId = '<workspace-id>'
$datasetId = '<dataset-id>'
$body = '{"notifyOption":"MailOnFailure"}'
Invoke-PowerBIRestMethod -Method Post -Url "groups/$groupId/datasets/$datasetId/refreshes" -Body $bodyUse NoNotification in notifyOption if you do not want email. For datasets in a personal workspace, omit the groups/$groupId/ part of the URL.
Inspect the history
Read the result with a GET on the same path. The $top option limits how many attempts come back.
Invoke-PowerBIRestMethod -Method Get -Url "groups/$groupId/datasets/$datasetId/refreshes?`$top=5"The response is JSON with a value array. Each entry matches a row in the portal's refresh history.
| Field | Meaning |
|---|---|
| `refreshType` | How it started, for example `Scheduled`, `OnDemand`, or `ViaApi` |
| `status` | `Unknown` while running, then `Completed` or `Failed` |
| `startTime`, `endTime` | UTC timestamps. `endTime` is missing while running |
| `serviceExceptionJson` | Error details when the status is `Failed` |
Change the schedule
The Update Refresh Schedule call is a PATCH to groups/{groupId}/datasets/{datasetId}/refreshSchedule. Note that the settings sit inside a value object.
{
"value": {
"enabled": true,
"days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
"times": ["07:00", "13:00"],
"localTimeZoneId": "UTC",
"notifyOption": "MailOnFailure"
}
}Common errors
- 401 or 403: The signed-in account lacks write access to the dataset, or the tenant blocks the API.
- Refresh never starts: You may have hit the daily limit. On shared capacity, API-triggered refreshes count toward the 8-per-day limit covered in the limits chapter.
- Status
Failedright away: ReadserviceExceptionJson. Credential and gateway mapping errors appear here first. - Concurrent request rejected: Only one refresh runs per dataset at a time. Wait for the current one to finish.
Exercise
Your script posts a refresh and receives 202 Accepted. Two minutes later the data is still old. Which call do you make next, and which status value tells you the refresh is still running?
Show answer
Make a GET request on the dataset's refreshes endpoint, for example with $top=1, and check the newest entry. A status of Unknown means the refresh is still in progress. Completed or Failed means it has ended. If it failed, read serviceExceptionJson.