简体   繁体   中英

Created Powershell and using Invoke-PowerBIRestMethod to schedule Power BI Refresh but throws 403 error

I am using below code. I have replaced the credentials and other GUIDs with XXXX. Please let me know if I am missing anything. The Service principal has read/write perms on Datasets, Reports and Workspaces as mentioned by my security team.

Connect-PowerBIServiceAccount -ServicePrincipal -CertificateThumbprint XXXX -ApplicationId XXXX -Tenant XXXX 

$jsonbody = '{
  "value": {
    "days": [
      "Sunday",
      "Tuesday",
      "Friday",
      "Saturday"
    ],
    "times": [
      "07:00",
      "11:30",
      "16:00",
      "23:30"
    ],
    "localTimeZoneId": "UTC",
    "enabled": true
  }
}'

Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/groups/XXXX/datasets/XXXX/refreshSchedule' -Method PATCH -Body $jsonbody -ContentType application/json

Resolve-PowerBIError -Last

The above script throws below error

Powershell 错误

服务负责人的权限

After a ticket with Microsoft product team, I was able to crack the issue.

The first issue is that the Service Principal should be "Application permissions" type and not "Delegated". The Delegated Service Principal will throw 400 error.

The second part and the main reason for 403 - Forbidden error is that I need to takeover the dataset. It means that I shouldn't just be the admin of the Workspace but I need to first takeover dataset using Power BI REST API. After taking over only, I can perform other dataset related tasks with Service Principal authentication.

Overall the sequence will be

  1. Takeover Dataset
  2. Bind Data Gateway . (Service Principal will require access to this Data Source in the Gateway. There are many steps for this piece to work)
  3. Update Parameters (if any)
  4. Update Refresh Schedule

If anyone is trying something similar, then I have posted a blog with detailed implementation and steps including Powershell script here .

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