Requirement: Update PowerBI dataset schedule using Powershell script via a Service Principal. PowerBI API used. Refer: MicrosoftDocs
Error Message: "Message":"API is not accessible for application"
What I did:
Provided PowerBI application API permissions in Azure AD. Admin access given to Service Principal in PowerBI workspaces.
Put the SP in a AD Group. MAde this AD Group the Admin of the Power BI Workspace and Dataset (under Power BI Admin Settings)
Used access token generated using Service Principal. Invoke-RestMethod for API request.
$SecPasswd = ConvertTo-SecureString $ClientSecret -AsPlainText -Force $ClientCred = New-Object System.Management.Automation.PSCredential($ClientId,$SecPasswd) Connect-PowerBIServiceAccount -Tenant $tenantId -ServicePrincipal -Credential $ClientCred $accessToken = Get-PowerBIAccessToken $authHeader = @{'Content-Type'='application/json','Authorization'= $accessToken.Authorization} $uri="https://api.powerbi.com/v1.0/myorg/datasets/$datasetId/refreshSchedule" Invoke-RestMethod -Uri $uri –Headers $authHeader –Method Patch -Body ($jsonBase | ConvertTo-Json) -ContentType "application/json"
Observations:
Used datasetId of my workspace and run the script. 2 Scenarios:
- Using Service Principal access token in Authorization header. Got -
Forbidden 403 Error. "Message":"API is not accessible for application
. - When using access token generated with my user credentials in the Authorization header the script runs successfully.
- Tried various datasets in other workspaces
What permissions am I missing to update the datasets schedule using Service Principal?