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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jhcannon
Frequent Visitor

Update Dataflow Refresh Schedule with API using PowerShell

I am copying a complete workspace to another using PowerShell.  I've pieced together several scripts I found and filled in where I was missing things.  All that is working as I expect.  Now, I need to change a few things on the new dataflows.

 

First - I need to change the data gateway that it uses.  I have parameters in my dataflows for the server and database names.  Updated those in the script but it also needs the gateway set and I cannot find a way to do that with APIs.  Maybe I'm missing that - if so please point me in right direction.  Right now, I have my script pause so I can set manually and then proceed.  Not ideal, but it serves the purpose.

 

Next, I would like to add the refresh schedules to my dataflows.  I have tried the refeshSchedule (https://docs.microsoft.com/en-us/rest/api/power-bi/dataflows/update-refresh-schedule) but am getting errors. 

 

Here is my script :

 

$urir = [string]::Format("https://api.powerbi.com/v1.0/myorg/groups/{0}/dataflows/{1}/refreshSchedule", $destinationWorkspace.Id, $dfInfo.objectId);

$ApiRequestBody = @"
{
"value": {
"days": [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
"times": [
"12:00"
],
"notifyOption": "NoNotification",
"localTimeZoneId": "035",
"enabled": true
}
}
"@


Write-Host -ForegroundColor White ( [string]::Format("Request Body '{0}'", $ApiRequestBody ) );

Invoke-RestMethod -Uri $urir -Method PATCH -Body $ApiRequestBody;

 

 

Here is the output from my script :

 

Request Body ' {
"value": {
"days": [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
"times": [
"12:00"
],
"notifyOption": "NoNotification",
"localTimeZoneId": "035",
"enabled": true
}
}'
Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type.


+ Invoke-RestMethod -Uri $urir -Method PATCH -Headers $headers -Body $ApiRequestBody;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc

eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

 

I've tried ConvertTo-Json / ConvertFrom-Json - same error message.  I know my ids in the variables are correct.  I've used same ones to do a single refresh and those work fine.

 

My gut is it has something to do with the PATCH method but I do not know where to even start on that.

 

1 ACCEPTED SOLUTION
jhcannon
Frequent Visitor

Just in case anyone else happens upon this and is having the same issue, I have found the solution.

 

I was missing the content-type in the header.

 

$headers = @{
'Authorization' = "$bearer"
'Content-Type' = "application/json"
}

View solution in original post

1 REPLY 1
jhcannon
Frequent Visitor

Just in case anyone else happens upon this and is having the same issue, I have found the solution.

 

I was missing the content-type in the header.

 

$headers = @{
'Authorization' = "$bearer"
'Content-Type' = "application/json"
}

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.