<?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: update-refresh-schedule-in-group error 415 Unsupported media type using powershell in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4279211#M58249</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/635694"&gt;@SofBL&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you to try code as below.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod -Url 'groups/groupid.../datasets/datasetid.../refreshSchedule' -Method PATCH -Body ([pscustomobject]@{
  "value"= [ordered]@{
  "days"= @("Sunday")
  "times"= @("08:00","16:00")
  }
} | ConvertTo-Json -Depth 2 -Compress)&lt;/LI-CODE&gt;
&lt;P&gt;For reference:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/powershell/power-bi/overview?view=powerbi-ps&amp;amp;toc=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fpower-bi%2Fenterprise%2Ftoc.json&amp;amp;bc=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fpower-bi%2Fbreadcrumb%2Ftoc.json#call-the-power-bi-rest-api" target="_blank"&gt;Power BI Cmdlets reference | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2024 06:05:52 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-11-12T06:05:52Z</dc:date>
    <item>
      <title>update-refresh-schedule-in-group error 415 Unsupported media type using powershell</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4278753#M58246</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Using the script below I try to update a dataset refresh schedule I Think this thing is OK I tried all kind of variations on it. but it keeps responding&amp;nbsp;Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type. at&amp;nbsp;Documents\Powershell\UpdateRefreshSchedule.ps1:33 char:13&lt;/P&gt;&lt;P&gt;+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException&lt;BR /&gt;+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand&lt;/P&gt;&lt;P&gt;I did other scripts with POST that also included a body and the same header and those worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As well as I am the owner of the schedule&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any ideas how to fix this will be apreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;# https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/update-refresh-schedule-in-group

## once in a lifetime you got to do this:
## Install-Module -Name MicrosoftPowerBIMgmt
## somtimes in a lifetime you got to do this:
## Update-Module -Name MicrosoftPowerBIMgmt
## Depending on your execution policy do not forget to trust the session
## Set-ExecutionPolicy -ExecutionPolicy remotesigned -Scope Process

## login to the platform
Login-PowerBI
#Get a token
$headers = Get-PowerBIAccessToken


#Fill in your workspace and dataset id below
$workspaceid = '74601087-ad5e-481c-a20c-1965baa8607b'
$datasetid = 'd469f67e-4568-49eb-b6bc-e42f2c5d37d5'

#Create a json body
$Body = @{
"value"= [ordered]@{
"days"= @("Sunday")
"times"=@("08:00","08:30")
"enabled"=$false
"localTimeZoneId"=@("Central Standard Time")
"notifyOption"=@("MailOnFailure")
}} | ConvertTo-Json

#change the schedule dataset
$uri = (ForEach-Object {'https://api.powerbi.com/v1.0/myorg/groups/{0}/datasets/{1}/refreshSchedule' -F $workspaceid,$datasetid })

$response = Invoke-RestMethod -Uri $uri -Method "PATCH" -Headers $headers -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>Mon, 11 Nov 2024 22:00:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4278753#M58246</guid>
      <dc:creator>SofBL</dc:creator>
      <dc:date>2024-11-11T22:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: update-refresh-schedule-in-group error 415 Unsupported media type using powershell</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4279211#M58249</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/635694"&gt;@SofBL&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you to try code as below.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod -Url 'groups/groupid.../datasets/datasetid.../refreshSchedule' -Method PATCH -Body ([pscustomobject]@{
  "value"= [ordered]@{
  "days"= @("Sunday")
  "times"= @("08:00","16:00")
  }
} | ConvertTo-Json -Depth 2 -Compress)&lt;/LI-CODE&gt;
&lt;P&gt;For reference:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/powershell/power-bi/overview?view=powerbi-ps&amp;amp;toc=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fpower-bi%2Fenterprise%2Ftoc.json&amp;amp;bc=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fpower-bi%2Fbreadcrumb%2Ftoc.json#call-the-power-bi-rest-api" target="_blank"&gt;Power BI Cmdlets reference | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 06:05:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4279211#M58249</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-12T06:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: update-refresh-schedule-in-group error 415 Unsupported media type using powershell</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4279920#M58261</link>
      <description>&lt;P&gt;Thanks for helping! The biggest error I made is that I included the -headers and that is not necessary&amp;nbsp; Secondly I used the Invoke-RestMethod, you suggest using Invoke-PowerBIRestMethod&amp;nbsp;&lt;BR /&gt;according to the docs&lt;/P&gt;&lt;P&gt;Invoke-RestMethod likes to have the -body formatted as an &amp;lt;object&amp;gt; and does not need the -headers&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Invoke-PowerBIRestMethod wants the -body&lt;/SPAN&gt;&amp;nbsp;as an &amp;lt;string&amp;gt; and needs the header&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 14:46:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4279920#M58261</guid>
      <dc:creator>SofBL</dc:creator>
      <dc:date>2024-11-12T14:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: update-refresh-schedule-in-group error 415 Unsupported media type using powershell</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4280005#M58262</link>
      <description>&lt;P&gt;&lt;A href="https://github.com/mschoombee/Blog/blob/main/2020/automating-power-bi-deployments/Reports%20-%20Update%20Refresh%20Schedule.ps1" target="_blank"&gt;https://github.com/mschoombee/Blog/blob/main/2020/automating-power-bi-deployments/Reports%20-%20Update%20Refresh%20Schedule.ps1&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;on this github site I found the solution.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;# https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/update-refresh-schedule-in-group

## once in a lifetime you got to do this: 
## Install-Module -Name MicrosoftPowerBIMgmt
## somtimes in a lifetime you got to do this:
## Update-Module -Name MicrosoftPowerBIMgmt
## Depending on your execution policy do not forget to trust the session
## Set-ExecutionPolicy -ExecutionPolicy remotesigned -Scope Process

## login to the platform
Login-PowerBI

##Build the body
 $ApiRequestBody = @"
        {
            "value": {
                "days": [
                    "Sunday",
                    "Monday",
                    "Tuesday",
                    "Wednesday",
                    "Thursday",
                    "Friday",
                    "Saturday"
                ],
                "times": [
                    "08:00",
                    "08:30"
                ],
                "notifyOption": "MailOnFailure", 
                "localTimeZoneId": "UTC", 
                "enabled": true
            }
        }
"@ 

## Invoke the API but do not include the header
Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/groups/74601087-ad5e-481c-a20c-1965baa8607b/datasets/d469f67e-4568-49eb-b6bc-e42f2c5d37d5/refreshSchedule' -Method Patch -Body ("$ApiRequestBody")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to schedule between full and half hours but then the response is&amp;nbsp;&lt;BR /&gt;Invoke-PowerBIRestMethod : Encountered errors when invoking the command: {&lt;BR /&gt;"code": "InvalidRequest",&lt;BR /&gt;"message": "Refresh schedule time must be full or half hour (HH:00 or HH:30)" so if you can live with that this is the solution&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 14:38:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/update-refresh-schedule-in-group-error-415-Unsupported-media/m-p/4280005#M58262</guid>
      <dc:creator>SofBL</dc:creator>
      <dc:date>2024-11-12T14:38:00Z</dc:date>
    </item>
  </channel>
</rss>

