The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I am trying to integrate powerbi reports into salesforce using app own data embedding. Below is the apex code which makes GET REST API call to powerbi to recieve embed token. The same code is retreieving embed token for paginated report but not for powerBIreport. I get 400 /Bad Request error when i try to generate embed token for powerBIreport.
Please help and thanks in advance!
// Call to Power BI Service API to get embed token for report
HttpRequest reqGetEmbedToken = new HttpRequest();
reqGetEmbedToken.setMethod('POST');
String urlGetEmbedToken = 'https://api.powerbi.com/v1.0/myorg/groups/' + WorkspaceId + '/reports/' + ReportId + '/GenerateToken';
reqGetEmbedToken.setEndpoint(urlGetEmbedToken);
reqGetEmbedToken.setHeader('Authorization', 'Bearer ' + access_token);
reqGetEmbedToken.setBody('{"accessLevel": "View", "datasetId": "' + powerBiReport.datasetId + '"}');
HttpResponse responseEmbedToken = http.send(reqGetEmbedToken);
// check response for success
if(responseEmbedToken.getStatusCode()!=200){
System.debug('ERROR --- Getting Embed Token --- ERROR');
System.debug('Status Code: ' + responseEmbedToken.getStatusCode());
PowerBiReportData getEmbedTokenError = new PowerBiReportData();
getEmbedTokenError.error = 'Get Embed Token Error: ' + response.getStatus();
return getEmbedTokenError;
}
Hi @nikitha ,
There could be multiple reasons for the error. Usually the response body has additional info, you can try to see if it helps understanding the reason.
datasetId isn't mandatory in the request body since you ask for accessLevel "View" and not "Create", but I doubt it's the reason for the failure.