The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hello experts,
I'm fairly new to working with API. I've been trying this out without success and in need of assistance to see what went wrong and how could I fix it.
Powershell with Service Principle account is being used to perform this task, I believe all needed permission has been granted via Azure Active Directory.
Process
Script of the PowerShell
$Workspacename = xxx
$Datasetname = xxx
$ClientID = xxx
$ClientSecret = xxx
$TenantID = xxx
$applicationId = $ClientID # Need to pass the clientid from devops variable
$clientsec = $ClientSecret | ConvertTo-SecureString -AsPlainText -Force # Need to pass from devops secret variable
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec
#Install-Module -Name MicrosoftPowerBIMgmt.Profile -Verbose -Scope CurrentUser -Force
#Install-Module -Name MicrosoftPowerBIMgmt.Workspaces -Verbose -Scope CurrentUser -Force
$Connect = Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -Environment Public -Tenant $TenantID
$workspace = Get-PowerBIWorkspace -Name $Workspacename
$DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json
$datasets = $DatasetResponse.value
foreach($dataset in $datasets){
if($dataset.name -eq $Datasetname){
$datasetid= $dataset.id;
break;
}
}
Invoke-PowerBIRestMethod -URL "groups/$($Workspace.id)/datasets/$($Dataset.id)/Default.TakeOver" -Method Post
$DisableScriptJson = @{
value= @{
enabled= "false"
}
} | ConvertTo-Json
Invoke-PowerBIRestMethod -URL "groups/$($Workspace.id)/datasets/$($Dataset.id)/refreshSchedule" -METHOD Patch -Body $DisableScriptJson | ConvertFrom-Json
Error
Invoke-PowerBIRestMethod : One or more errors occurred.
At line:42 char:2
+ Invoke-PowerBIRestMethod -URL "groups/$($Workspace.id)/datasets/$($D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
Any help is appreciated, let me know if further information is needed
Hi @zuheirashraf17 ,
Do you have permissions for read and write?
My understanding is that in order for the API to work it actually has to write permissions with the dataset.
Before you run this command, make sure you log in using Connect-PowerBIServiceAccount.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello Liang/@V-lianl-msft , appreciate your reply.
As for the permission, I believe this should be enough right?
As for Connect-PowerBIServiceAccount, it was able to connect just fine, please see my script. And the service account has admin access to the workspace too. In fact it was able to take over the dataset, but fail when trying to update/disable the refresh schedule.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
18 | |
2 | |
2 | |
1 | |
1 |