powerbipowerbi-api

How to create a Power BI DataSet Scheduled Refresh programatically


Requirement: To create a Power BI Dataset scheduled refresh through code and use it in DevOps process, so that I do not have to create scheduled refresh explicitly from Power BI web portal.

What I tried/research: I could not find Power BI API explicitly to create scheduled refresh. So, I tried to use update refresh schedule datasets API: https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/refreshSchedule Refer: MicrosoftDocs

Observed: If the schedule is OFF - this API turns ON the schedule and updates the refresh schedule of the dataset. However, to achieve this I had to create schedule at least once using the Power BI web portal. Then if I turn off the schedule and run the above API, it turns ON the schedule and updates refresh schedule timings.

Are any workarounds to setup a Power BI Dataset scheduled refresh via API?


Solution

  • Yes there is by using the 'Update refresh schedule in group' endpoint:

    https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/refreshSchedule

    Refer: Microsoft

    In the body you can specify your schedule. I use this in a python script to set my schedules automatically. As body I use:

     {"value": 
        {"days":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
         "times": ["05:00"],
         "enabled": 'true',
         "localTimeZoneId": "UTC"
      }}