Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 9 | |
| 4 | |
| 4 | |
| 4 | |
| 3 |