Forum Discussion
Automate Dataset Refresh with PowerShell Scripts
Hi raghav20 ,
You are refreshing the Power BI dataset by invoking the REST API through the service principal.
The service principal needs to be added with the Dataset.ReadWrite.All API permission.
Then, the /Service principals can use Fabric APIs/ feature needs to be enabled in the admin portal.
Finally, as this superuser lbendlin said, the notifyOption body may needs to be specified when using POST.
Datasets - Refresh Dataset In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous , Thanks for the response after i have received appropriate permissions from App, I was able run the scripts and Dataset refresh is happening for few reports.
I have some challenge here, i was unable to refresh couple of Datasets. These datasets were connected with another semantic model as Direct Query. Connection flow as below
Source -> Dataflow ->Semantic Model 1 (Import mode) ->Semantic Model 2 (Direct Query)->Report
Semantic Model1 is a Just model it has custom fields and actual columns from the source
Semantic Model 2 -- Report All visuals are avilable here.
In order to see the latest Data in Report i need to refersh Semantic Model 1 & Semantic Model 2.
I was able to refresh Semantic Model 1 without any issues but, when i try to refersh Semantic Model 2 with same PowerShell script, i am getting below error.
C:\Data\Files\PShell\Refresh_Dataset.ps1 : Failed to initiate dataset refresh: The remote server returned an
error: (415) Unsupported Media Type..Exception.Message
At line:1 char:1
+ .\Refresh_Dataset.ps1 -workspace POC -dataset Report_Model
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Refresh_Dataset.ps1
Response Body: {"error":{"code":"InvalidRequest","message":"Invalid dataset. This API
can only be called on a Model-based dataset"}}
How can i make my script to work for other Dataset as well, is there any way to make it work ? Thanks in advance!
- lbendlin1 year ago
Super User
You are only allowed to request refreshes for semantic models that you own.
- raghav201 year agoFrequent Visitor
Hey lbendlin Thanks for quick response! Above case both the models I own.
- lbendlin1 year ago
Super User
Do you get an error message when you try this in the API sandbox?
Datasets - Refresh Dataset In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn