To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi @all
I have developed an api to interact with power bi to show the report in Salesforce. I a getting following exception.
2. Anyone can access the API in Power BI tenant settings.
3. I am getting access token using following code.
Power_BI_Auth_Settings__mdt authSetting = Power_BI_Auth_Settings__mdt.getInstance('PowerBiApp');
string TenantId = authSetting.TenantId__c;
string ClientId = authSetting.ClientId__c;
string ClientSecret = authSetting.ClientSecret__c;
// construct URL for client credentials flow
String aadTokenEndpoint = 'https://login.microsoftonline.com/' + TenantId + '/oauth2/v2.0/token';
// prepare HTTP request
HttpRequest reqClientCredentialsFlow = new HttpRequest();
reqClientCredentialsFlow.setMethod('POST');
reqClientCredentialsFlow.setEndpoint(aadTokenEndpoint);
reqClientCredentialsFlow.setHeader('Content-Type', 'application/x-www-form-urlencoded');
// compose data for POST body
ClientCredentialPostData postData = new ClientCredentialPostData();
postData.client_id = ClientId;
postData.client_info = '1';
postData.client_secret = ClientSecret;
postData.scope = 'https://analysis.windows.net/powerbi/api/.default';
postData.grant_type = 'client_credentials';
String postBody = postData.getPostData();
reqClientCredentialsFlow.setBody(postBody);
// send HTTP POST to execute client credentials flow
Http http = new Http();
HttpResponse response = http.send(reqClientCredentialsFlow);
// extract and return app-only access token for service principal
String responseJson = response.getBody();
ClientCredentialResponse responseData = (ClientCredentialResponse)JSON.deserialize(responseJson, ClientCredentialResponse.class);
String access_token = responseData.access_token;
return access_token;
}
4. But when I am accessing https://api.powerbi.com/v1.0/myorg/groups/' + WorkspaceId + '/reports , I am getting the error mentioned above.
// get access token for Authorization header
String access_token = getPowerBiAccessToken();
// Call to Power BI Service API to get report data for embedding
HttpRequest reqGetReport = new HttpRequest();
reqGetReport.setMethod('GET');
String urlGetReport = 'https://api.powerbi.com/v1.0/myorg/groups/' + WorkspaceId + '/reports';
reqGetReport.setEndpoint(urlGetReport);
reqGetReport.setHeader('Authorization', 'Bearer ' + access_token);
Http http = new Http();
HttpResponse response = http.send(reqGetReport);
System.debug(response.getBody());
// check response for success
if(response.getStatusCode()!=200){
System.debug('ERROR --- Getting Report Data --- ERROR');
System.debug('Status Code: ' + response.getStatusCode());
PowerBiReportData getReportError = new PowerBiReportData();
getReportError.error = 'Get Report Error: ' + response.getStatus();
return getReportError;
}
Please help into this. I have tried everything from my side. May be this can help to others as well.
Thanks,
Aman Muskan
@Anonymous Ya its correct. I was missing the workspace access for the created azure app. Reports are coming but App access I am not getting. I am using https://api.powerbi.com/v1.0/myorg/apps. Can I get a whole application from Power Bi using this API ?
Please comment once.
1. I have given App.Read.All and Group.Read.All and its showing "API is not accessible for application".
HI @amanmuska,
AFIAK, PowerBINotAuthorizedException is an error message that displayed when you don’t have the proper permissions to perform an action in Power BI.
For this scenario, you may need to double check on the pension and correspond scope settings of assign suitable permission instead directly assign all type and level of permissions. (sometime these different level permissions may conflict and effect the feature usages)
Regards,
Xiaoxin Sheng
User | Count |
---|---|
3 | |
3 | |
2 | |
2 | |
2 |
User | Count |
---|---|
9 | |
7 | |
6 | |
5 | |
4 |