PowerBI API 使用服务主体更新数据集时出错

Kar*_*ngh 4 powerbi service-principal powerbi-api

要求:通过服务主体使用 Powershell 脚本更新 PowerBI 数据集计划。使用 PowerBI API。参考:微软文档

\n

错误消息:“消息”:“应用程序无法访问 API”

\n

我做了什么:

\n
    \n
  1. 在 Azure AD 中提供了 PowerBI 应用程序 API 权限。向 PowerBI 工作区中的服务主体授予管理员访问权限。

    \n

    API权限

    \n
  2. \n
\n
    \n
  1. 将 SP 放入 AD 组中。将此 AD 组设为 Power BI 工作区和数据集的管理员(在 Power BI 管理设置下)

    \n
  2. \n
  3. 使用使用服务主体生成的访问令牌。针对 API 请求调用 RestMethod。

    \n
    $SecPasswd = ConvertTo-SecureString $ClientSecret -AsPlainText -Force\n$ClientCred = New-Object System.Management.Automation.PSCredential($ClientId,$SecPasswd)\n\nConnect-PowerBIServiceAccount -Tenant $tenantId -ServicePrincipal -Credential $ClientCred\n$accessToken = Get-PowerBIAccessToken\n$authHeader = @{\'Content-Type\'=\'application/json\',\'Authorization\'= $accessToken.Authorization}\n$uri="https://api.powerbi.com/v1.0/myorg/datasets/$datasetId/refreshSchedule"\nInvoke-RestMethod -Uri $uri \xe2\x80\x93Headers $authHeader \xe2\x80\x93Method Patch -Body ($jsonBase | ConvertTo-Json) -ContentType "application/json"\n
    Run Code Online (Sandbox Code Playgroud)\n
  4. \n
\n

观察结果:

\n

使用我的工作区的 datasetId 并运行脚本。2个场景:

\n
    \n
  1. 在授权标头中使用服务主体访问令牌。得到 - Forbidden 403 Error. "Message":"API is not accessible for application
  2. \n
  3. 当使用授权标头中使用我的用户凭据生成的访问令牌时,脚本成功运行。
  4. \n
  5. 尝试了其他工作区中的各种数据集
  6. \n
\n

我缺少哪些权限来使用服务主体更新数据集计划?

\n

Nei*_*l P 11

Microsoft API 文档中的 URL 对于服务主体来说是错误的。

您还需要在 URL 中包含工作区 ID,请参见下文

https://api.powerbi.com/v1.0/myorg/groups/{WorkspaceID}/datasets/{DatasetId}refreshes
Run Code Online (Sandbox Code Playgroud)