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
h4tt3n
Helper V
Helper V

Keep getting a 400 Bad Request error when trying to update refresh schedule via API

Hello folks,

 

I am developing Power BI reports and managing them via API calls as a part of my job. I have developed a number of powershell scripts to streamline management via the rest API. It all works pretty well, except when I attempt to update a refresh schedule of a report. Some details:

 

  • Enabling scheduled refresh is done separately and is not a problem
  • I have taken over or is aleady the dataset owner.
  • Updating the refresh schedule consistently returns a 400 Bad Request error.

Here are the PS functions:

 

 

function EnableDatasetRefreshSchedule
{
    [CmdLetBinding()]
    param 
    ( 
        [Parameter(Mandatory=$true, Position=0)] [string] $groupId, 
        [Parameter(Mandatory=$true, Position=1)] [string] $datasetId, 
        [Parameter(Mandatory=$true, Position=2)] [string] $refreshScheduleState 
    )

    $urlRefreshScedule = "https://api.powerbi.com/v1.0/myorg/groups/$groupId/datasets/$datasetId/refreshSchedule"

    $body = '{ "value": {"enabled": '+$refreshScheduleState+' }}'

    Invoke-PowerBIRestMethod -Url $urlRefreshScedule -Body $body -Method PATCH
}

function UpdateDatasetRefreshScheduleTime
{
    [CmdLetBinding()]
    param 
    ( 
        [Parameter(Mandatory=$true, Position=0)] [string] $groupId, 
        [Parameter(Mandatory=$true, Position=1)] [string] $datasetId, 
        [Parameter(Mandatory=$true, Position=2)] [string] $refreshScheduleDays, 
        [Parameter(Mandatory=$true, Position=3)] [string[]] $refreshHours, 
        [Parameter(Mandatory=$true, Position=4)] [string[]] $refresMinutes 
    )

    $randomHour = $refreshHours | Get-Random
    $randomMinute = $refresMinutes | Get-Random

    $refreshScheduleTime = '"'+$randomHour+':'+$randomMinute+'"'

    $urlRefreshScedule = "https://api.powerbi.com/v1.0/myorg/groups/$groupId/datasets/$datasetId/refreshSchedule"

    #$body = '{ "value": {"days": ['+$refreshScheduleDays+'], "times": ['+$refreshScheduleTime+'],"localTimeZoneId": "UTC"}}'
    $body = '{"value": {"days": ['+$refreshScheduleDays+'], "times": ['+$refreshScheduleTime+']}}'

    Invoke-PowerBIRestMethod -Url $urlRefreshScedule -Body $body -Method PATCH
}

 

Any hints on what  might be wrong is very appreciated!

 

Cheers, Mike

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Always test your API calls in the sandbox. 

Datasets - Update Refresh Schedule In Group (Power BI Power BI REST APIs) | Microsoft Docs

 

Refreshes can only be scheduled at :00 and :30 (top and bottom of hour). You can't supply a random minute number.

View solution in original post

5 REPLIES 5
lbendlin
Super User
Super User

This works for me:

 

 

$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

 

 

 

shubhamquick
Regular Visitor

Hi,

 

Trying to automate the schedule refresh enable portion once they are in disable state.

Using below code:-

$refreshScheduleState ="true"

$urlRefreshScedule = "https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}/refreshSchedule"

$body = '{ "value": {"enabled": '+$refreshScheduleState+' }}'

Invoke-PowerBIRestMethod -Url $urlRefreshScedule -Body $body -Method PATCH

 

But getting error while running this code.

 

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:2
+ Invoke-PowerBIRestMethod -Url $urlRefreshScedule -Body $body -Method ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:I
nvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.C
ommands.Profile.InvokePowerBIRestMethod

 

Kindly suggest

Try: 

 

$refreshScheduleState = '"true"'

 

Cheers, Mike

h4tt3n
Helper V
Helper V

@lbendlin 

"Refreshes can only be scheduled at :00 and :30 (top and bottom of hour). You can't supply a random minute number."

This indeed was the problem. Unfortunately, it appears thet the official documentation does not cover this crucial detail. Also, the error returned simply states "Bad request", which is not very helpful. But your reply was, thank you.

Cheers, Mike

lbendlin
Super User
Super User

Always test your API calls in the sandbox. 

Datasets - Update Refresh Schedule In Group (Power BI Power BI REST APIs) | Microsoft Docs

 

Refreshes can only be scheduled at :00 and :30 (top and bottom of hour). You can't supply a random minute number.

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.