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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.