1

我尝试通过将发布请求发送到 PBI API 端点以编程方式刷新 Power BI Premium 数据集:datasets//refreshes。

文档 ( https://docs.microsoft.com/en-us/power-bi/connect-data/asynchronous-refresh ) 指出: 响应还包括一个 location response-header 字段,用于将调用者指向刷新操作刚刚创建/接受。位置是请求创建的新资源的位置,其中包括 refreshId。

我需要 refreshId 来轮询其状态以确定它是否成功。

我使用以下 Powershell 代码刷新数据集。

请让我知道如何在响应标头中返回位置字段。

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 

我认为 Invoke-PowerBIRestMethod 没有 header 属性。我使用 Invoke-WebRequest 尝试了相同的操作并包含了响应。


$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

响应(状态码为 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
4

2 回答 2

0

POST 刷新后,为什么不检查 GET 方法中是否有任何新的 requestID?

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

应该有一个“refreshType”:“ViaApi”和StartTime,以及状态“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"
    }
  ]
}
于 2022-01-29T17:31:39.653 回答
0

也许尝试删除请求正文中的“刷新”层。从公共文档来看,它似乎不包含这一层。并且还在请求标头中设置“Content-Type: application/json”。

于 2022-01-20T03:05:59.237 回答