I try to refresh a Power BI Premium dataset programmatically by sending post request to PBI API endpoint: datasets//refreshes.
The documentation (https://learn.microsoft.com/en-us/power-bi/connect-data/asynchronous-refresh) states: The response also includes a location response-header field to point the caller to the refresh operation that was just created/accepted. Location is that of the new resource which was created by the request, which includes the refreshId.
I need the refreshId in order to poll its status to determine whether it has succeeded.
I used the following Powershell code to refresh the dataset.
Please let me know how I can return the location field in the response header.
Login-PowerBI
$XmlaQuery = @"
{
"refresh": {
"type": "full",
"objects": [
{
"database": "<Datamodel>",
"table": "<Table>"
}
]
}
}
"@
# URL is a relative or absolute URL of the Power BI entity to access.
Invoke-PowerBIRestMethod -Url 'datasets/<datasetid>/refreshes' -Method Post -Body $XmlaQuery
I figured that Invoke-PowerBIRestMethod does not have the header property. I tried the same using Invoke-WebRequest and included the response.
$XmlaQuery = @"
{
"refresh": {
"type": "full",
"objects": [
{
"database": "<Datamodel>",
"table": "<Table>"
}
]
}
}
"@
# URL is a relative or absolute URL of the Power BI entity to access.
Login-PowerBIServiceAccount
$headers = Get-PowerBIAccessToken
$Response = Invoke-WebRequest -Uri 'https://api.powerbi.com/v1.0/myorg/groups/<workspaceid>/datasets/<datasetid>/refreshes' -Method Post -Body $XmlaQuery -Headers $headers
$Response.Headers | Format-Table
$Response.StatusCode
Response (with status code 202):
Key Value
--- -----
Pragma no-cache
Transfer-Encoding chunked
Strict-Transport-Security max-age=31536000; includeSubDomains
X-Frame-Options deny
X-Content-Type-Options nosniff
RequestId <RequestId>
Access-Control-Expose-Headers RequestId
request-redirected true
home-cluster-uri https://wabi-north-europe-f-primary-redirect.analysis.windows.net/
Cache-Control no-store, must-revalidate, no-cache
Content-Type application/octet-stream
Date Mon, 17 Jan 2022 16:09:30 GMT