Forum Discussion

KetanB's avatar
KetanB
Frequent Visitor
7 years ago
Solved

Is there any REST API to Refresh Data for PBIX files existing on Power BI Report Server?

Hi Friends,   I am working on REST APIs for Power BI Report Server. I could upload a report (Power BI Dashboard) using REST APIs.   Now, I am curious to know if we have any APIs to set the schedu...
  • Anonymous's avatar
    Anonymous
    7 years ago

    If your objective is to force a data refresh for a PBIX file there are a couple of approaches to this.

     

    Every scheduled refresh becomes a SQL Agent job with a transact SQL command that looks somehting like this

    exec [ReportServer].dbo.AddEvent @EventType='DataModelRefresh', @EventData='ac452376-cfda-4772-8cf4-6b5a59ea321b'

    The GUID in @EventData is the SubscriptionID from the dbo.Subscription Table. You can also use this subscriptionID to query the dbo.ReportSchedule table which will give you the ScheduleID which is the GUID used for the name of the SQL Agent Job that gets built on the SQL Server that actually runs the refresh. The same server as the ReportServer DB backend.

     

    If you can fugure out the ID (GUID) of the PBIX (look it up in dbo.catalog) this gives you access to the subscription via the Report_OID column in the dbo.Subscriptions table.

     

    So you could run some dirty PowerShell and some SQL queries to get you to the SubscriptionID GUID you need then just send the relevant SQL command to the backend Server.

     

    This is really really not supported and will produce howls of anguish as being a dirty hack!

     

    As an alternative I think you can trigger it via the REST API.

     

    You can find the cache refresh plan for a report via the REST API like this

     

    http://localhost/reports/api/v2.0/PowerBIReports(6654B9C1-8A84-432E-BC5F-883103A22832)/CacheRefreshPlans

    Which gives you the ID of the cacheRefreshPlan. You can obviously figure out the reportID (GUID) using the REST-API

     

    You can then access the cacherefreshplan using this

    http://localhost/reports/api/v2.0/CacheRefreshPlans(ac452376-cfda-4772-8cf4-6b5a59ea321b)

    Now the swagger documentation says you can make the cache refresh plan run using a POST request to

     

    http://localhost/reports/api/v2.0/CacheRefreshPlans(ac452376-cfda-4772-8cf4-6b5a59ea321b)/Model.Execute

    Having just poked this on something here it seems to work. Though the data hasn't moved so I've no menaingful way to tell.

     

    I get an error if I try and run the Model.Execute off the end of the PBIReport/cacherferhsplans like this

     

    http://localhost/reportsI/api/v2.0/PowerBIReports(6654B9C1-8A84-432E-BC5F-883103A22832)/CacheRefreshPlans(ac452376-cfda-4772-8cf4-6b5a59ea321b)/Model.Execute

    But the CacheRefreshPlans stuff seems to work as per the swagger docs