简体   繁体   中英

Async refresh Power BI REST API: Response doesn't include location field that should contain refreshId

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.

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

Perhaps try removing the "refresh" layer in the request body. From the public documentation, it doesn't seem to contain this layer. And also setup "Content-Type: application/json" in the request header.

Adding a bounty, really need to get this solved

After you POST refresh, why do you just not check if is there any new requestID from GET method?

GET https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/refreshes?$top={$top}

there should be a "refreshType": "ViaApi" and StartTime, and Status "inProgress"/"Completed"/"not started"

{
  "value": [
    {
      "refreshType": "ViaApi",
      "startTime": "2017-06-13T09:25:43.153Z",
      "endTime": "2017-06-13T09:31:43.153Z",
      "status": "Completed",
      "requestId": "9399bb89-25d1-44f8-8576-136d7e9014b1"
    }
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM