Refresh all datasets with a single button through the Power BI REST API using Python script
Power BI REST APIs
When we have few questions about the Power BI environment we want answers to, such as:
How many reports are deployed? Who are the users for each workspace? Which datasets, dataflows are deployed in a workspace? and all types of questions about operations of: Admin , Apps, Capacities, Dashboards, Dataflows datasets,groups, users, apps, pipelines,....
👍The Power BI REST APIs provide service endpoints that give us all types of responses for managing Power BI content, performing admin operations and embedding Power BI Content.
Querying the Power BI REST API
The API allows us to bypass the web interface of Power BI Service and ask questions directly to the back-end of the service. To query the API, we can use:
Powershell Cmdlets: which are a set of Powershell commands which need to be installed on our machines (adam vieo explains how it's done) and which return results in a standard way
C# application code which can read the JSON response from the API
Any other programming languages capable of making a web request and parsing a JSON response like Python,…
Querying the API with Python script to refresh all datasets
In this example of Parker from BI ELITE, he shows how to accomplish the refresh of all datasets across all workspaces via the POWER BI REST API through a Python script, which will retrieve the list of all available workspaces then retrieve the list of datasets in each group and run a refresh task for each dataset;
After having developed the script, we will need to run it on a Python interpreter. This could be done inside the Power BI desktop ( pre-install python locally ) by choosing “Python script” from the proposed sources, and then publish the PBIX file, so that the code can be run from the Power BI Service.
=>Every time we refresh the dataset of the published report, it will trigger the Python script, resulting in the refresh of all datasets.