1

I have some client that uses the Power BI App.
And with this API I want to get all the reports (.pbix) to my folder.

How can I get them?

zx485
  • 28,498
  • 28
  • 50
  • 59

1 Answers1

1

You can simply open the report in your browser and save it as .pbix file:

enter image description here

If you want to do this using an API, you will need Export Report In Group REST API. To use it, you need to acquire an access token and add it to your request header. You can acquire it by calling some of the AcuireToken methods from ADAL.

You can use code like this (please note there is no error checking in the example):

string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Obtain at https://dev.powerbi.com/apps
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
string resourceUri = "https://analysis.windows.net/powerbi/api";
string authorityUri = "https://login.windows.net/common/oauth2/authorize";

AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache()); // PM> Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory

var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
var accessToken = authenticationResult.AccessToken);

string powerBIApiUrl = "https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportKey}/Export"; // Replace groupId and reportKey with actual values

var request = WebRequest.Create(powerBIApiUrl) as HttpWebRequest;
request.KeepAlive = true;
request.Method = "GET";
request.ContentLength = 0;
request.ContentType = "application/json";
request.Headers.Add("Authorization", $"Bearer {accessToken}");

using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
{
    //Read httpResponse.GetResponseStream() to get the .pbix file
}       
Andrey Nikolov
  • 12,967
  • 3
  • 20
  • 32
  • i want do to it using rest API - do you know what i need to enter in stand of "myorg" ? https://api.powerbi.com/v1.0/myorg/groups – user3173690 Dec 11 '18 at 10:04
  • `myorg` should stay `myorg`. You need to replace `{groupId}` and `{reportKey}` only. You can take these from the browser's address bar when the report is loaded. – Andrey Nikolov Dec 11 '18 at 11:06