<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Keep getting a 400 Bad Request error when trying to update refresh schedule via API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/2107657#M32162</link>
    <description>&lt;P&gt;Try:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$refreshScheduleState = '"true"'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers, Mike&lt;/P&gt;</description>
    <pubDate>Thu, 30 Sep 2021 08:28:20 GMT</pubDate>
    <dc:creator>h4tt3n</dc:creator>
    <dc:date>2021-09-30T08:28:20Z</dc:date>
    <item>
      <title>Keep getting a 400 Bad Request error when trying to update refresh schedule via API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/1691372#M28105</link>
      <description>&lt;P&gt;Hello folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Enabling scheduled refresh is done separately and is not a problem&lt;/LI&gt;&lt;LI&gt;I have taken over or is aleady the dataset owner.&lt;/LI&gt;&lt;LI&gt;Updating the refresh schedule consistently returns a 400 Bad Request error.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Here are the PS functions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any hints on what&amp;nbsp; might be wrong is very appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers, Mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 07:57:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/1691372#M28105</guid>
      <dc:creator>h4tt3n</dc:creator>
      <dc:date>2021-02-26T07:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Keep getting a 400 Bad Request error when trying to update refresh schedule via API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/1694035#M28127</link>
      <description>&lt;P&gt;Always test your API calls in the sandbox.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/updaterefreshscheduleingroup" target="_blank" rel="noopener"&gt;Datasets - Update Refresh Schedule In Group (Power BI Power BI REST APIs) | Microsoft Docs&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Refreshes can only be scheduled at :00 and :30 (top and bottom of hour). You can't supply a random minute number.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 02:40:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/1694035#M28127</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-02-28T02:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Keep getting a 400 Bad Request error when trying to update refresh schedule via API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/1695272#M28136</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/100342"&gt;@lbendlin&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;"&lt;SPAN&gt;Refreshes can only be scheduled at :00 and :30 (top and bottom of hour). You can't supply a random minute number."&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Cheers, Mike&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 06:58:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/1695272#M28136</guid>
      <dc:creator>h4tt3n</dc:creator>
      <dc:date>2021-03-01T06:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Keep getting a 400 Bad Request error when trying to update refresh schedule via API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/2107591#M32160</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to automate the schedule refresh enable portion once they are in disable state.&lt;/P&gt;&lt;P&gt;Using below code:-&lt;/P&gt;&lt;P&gt;$refreshScheduleState ="true"&lt;BR /&gt;&lt;BR /&gt;$urlRefreshScedule = "&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}/refreshSchedule" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}/refreshSchedule&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;$body = '{ "value": {"enabled": '+$refreshScheduleState+' }}'&lt;/P&gt;&lt;P&gt;Invoke-PowerBIRestMethod -Url $urlRefreshScedule -Body $body -Method PATCH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But getting error while running this code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Invoke-PowerBIRestMethod : One or more errors occurred.&lt;BR /&gt;At line:1 char:2&lt;BR /&gt;+ Invoke-PowerBIRestMethod -Url $urlRefreshScedule -Body $body -Method ...&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:I&lt;BR /&gt;nvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException&lt;BR /&gt;+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.C&lt;BR /&gt;ommands.Profile.InvokePowerBIRestMethod&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly suggest&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 08:03:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/2107591#M32160</guid>
      <dc:creator>shubhamquick</dc:creator>
      <dc:date>2021-09-30T08:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Keep getting a 400 Bad Request error when trying to update refresh schedule via API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/2107657#M32162</link>
      <description>&lt;P&gt;Try:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$refreshScheduleState = '"true"'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers, Mike&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 08:28:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/2107657#M32162</guid>
      <dc:creator>h4tt3n</dc:creator>
      <dc:date>2021-09-30T08:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Keep getting a 400 Bad Request error when trying to update refresh schedule via API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/2108776#M32175</link>
      <description>&lt;P&gt;This works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;$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&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 17:47:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Keep-getting-a-400-Bad-Request-error-when-trying-to-update/m-p/2108776#M32175</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-09-30T17:47:48Z</dc:date>
    </item>
  </channel>
</rss>

