microsoft / microsoft/powerbi-powershell
Async refresh Power BI REST API: response doesn't include location field that should contain refreshid
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 413
- Forks
- 134
- Avg merge
- 33m
- Merged PRs (30d)
- 1
Description
I try to refresh a Power BI Premium dataset programmatically by sending post request to PBI API endpoint: datasets//refreshes.
The documentation (https://docs.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, I feel like the implementation is stripping away the headers.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the POST with Invoke-PowerBIRestMethod and Invoke-WebRequest using the dataset refresh endpoint shown in the issue. Inspect how the PowerBI PowerShell command handles response headers and compare the returned headers with the documented Location field. Done means the refresh operation's Location or refreshId is available to callers, or the limitation is clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100