Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
zuheirashraf17
Advocate II
Advocate II

PowerShell Rest API /RefreshSchedule Patch doesn't work

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 

  1. Take Over Dataset - Success (Dataset was successfully taken over by the Service principle account)
  2. Disable Refresh Schedule - Fail (This is where the error shows up)

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

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

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?

zuheirashraf17_0-1622701010800.png

 

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. 

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.