Forum Discussion
update-refresh-schedule-in-group error 415 Unsupported media type using powershell
- 1 year ago
https://github.com/mschoombee/Blog/blob/main/2020/automating-power-bi-deployments/Reports%20-%20Update%20Refresh%20Schedule.ps1
on this github site I found the solution.# 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")I tried to schedule between full and half hours but then the response is
Invoke-PowerBIRestMethod : Encountered errors when invoking the command: {
"code": "InvalidRequest",
"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
Hi SofBL ,
I suggest you to try code as below.
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)
For reference: Power BI Cmdlets reference | Microsoft Learn
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- SofBL1 year ago
Advocate II
Thanks for helping! The biggest error I made is that I included the -headers and that is not necessary Secondly I used the Invoke-RestMethod, you suggest using Invoke-PowerBIRestMethod
according to the docsInvoke-RestMethod likes to have the -body formatted as an <object> and does not need the -headers
Invoke-PowerBIRestMethod wants the -body as an <string> and needs the header