Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
nikitha
New Member

GET Embed Token REST API is returning 400 Error

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;
}

1 REPLY 1
AmosHersch
Microsoft Employee
Microsoft Employee

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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.