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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Error using a service principal with Method Patch on PowerBI REST API to update refresh schedule

Hello, 

 

I'm facing an issue (bad request) using method patch with service principal on API REST PowerBI.

I'm currently working on a powershell script to deploy a pbix file with a service principal.

The script works fine. It does : 

- Connect to PowerBI Service

- Create report and dataset

- Update parameter (credentiels)

- BindToGateway (with principal service added to user of the gateway, thanks to Adam Saxton)

- Refresh

 

but impossible de UpdateRefreshSchedule. It's only API Call with Method Patch.

 

$ApiBindToGatewayUrl="https://api.powerbi.com/v1.0/" + $TenantId + "/groups/" + $WorkspaceObject.Id + "/datasets/" + $DatasetId + "/Default.BindToGateway"
Invoke-PowerBIRestMethod -Url $ApiBindToGatewayUrl -Method Post -Body ("$ApiBindToGatewayRequestBody")

Write-Host "Gateway bind end"`r`n

$headers = Get-PowerBIAccessToken


$ApiRefreshScheduleUrl = "https://api.powerbi.com/v1.0/" + $TenantId + "/groups/" + $WorkspaceObject.Id + "/datasets/" + $DatasetId + "/refreshSchedule"

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

Method 1 = Invoke-PowerBIRestMethod -Url $ApiRefreshScheduleUrl -Method Patch -Body ("$ApiRefreshScheduleRequestBody") | ConvertFrom-Json

Method 2 = Invoke-RestMethod -Uri $ApiRefreshScheduleUrl -Headers $headers -Method POST -Body ("$ApiRefreshScheduleRequestBody") -ContentType "application/json"

 

 

TarikGuetarni_0-1632995774923.png

 

4 REPLIES 4
linforda
Regular Visitor

Is there already a solution for this problem?

lbendlin
Super User
Super User

Your body data looks ok, but the inclusion parameter looks weird.  Try this format (adjust as needed):

 

 

$uri = “https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/datasets/$datasetID/refreshSchedule"
$body = "{ value : { enabled :`"true`” }}"
$res = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method PATCH -body $body

 

Anonymous
Not applicable

The thing is that the exact same code works when i try to connect with an identified user (not a service principal).

I'm wondering itf this feature is not supported with service principal

Anonymous
Not applicable

Hi,
I'm facing the same problem 😞
have you found a solution?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors