Forum Discussion
Unexpected Embed Token Format and Embedding Failure
Hello,
I have a question regarding the Power BI Embed Token.
According to the official documentation, the Embed Token should be returned in the following format:
{ "token": "H4sI....AAA=", "tokenId": "49ae3742-54c0-4c29-af52-619ff93b5c80", "expiration": "2018-07-29T17:58:19Z" }
(https://learn.microsoft.com/en-us/rest/api/power-bi/embed-token/generate-token)
However, the token I received is in the following format:
{
"@odata.context":"https://wabi-south-east-asia-redirect.analysis.windows.net/v1.0/myorg/$metadata#Microsoft.PowerBI.ServiceContracts.Api.V1.GenerateTokenResponse","token":"H4sIAAAAAAAEACWT.....9UU4Q0IGAAA=.eyJjbHVzdGVyVXJ....nRydWV9","tokenId":"70ed8690-4b40-41d3-b665-c5d1bf86e76f","expiration":"2025-03-18T02:46:43Z"
}
It appears that the compressed token and JWT token are concatenated with a dot (.). Additionally, the expected suffix "AAA=" has changed to "AAA==".
The response status code is 200, indicating a successful request.
I attempted embedding by extracting the compressed token from the received value, but it failed. I also tried embedding using the entire token, but it was unsuccessful.
Below is the error screen I encountered:
The message in Korean states: "This content is not available."
For reference:
- The app was successfully registered in Azure AD.
- API permissions have been granted.
- I have retrieved an access token using a refresh token.
String url = "https://login.microsoftonline.com/" + tenantId + "/oauth2/v2.0/token";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString("client_id=" + clientId +
"&client_secret=" + clientSecret +
"&refresh_token=" + refreshToken +
"&grant_type=refresh_token" +
"&scope=https://analysis.windows.net/powerbi/api/Report.ReadWrite.All"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
Generate Power BI Embed Token
String url = "https://api.powerbi.com/v1.0/myorg/GenerateToken";
String requestBody = "{\n" +
"\"datasets\": [\n" +
"{\n" +
"\"id\": \"0a141e78-e.....b07ed05c6\"\n" +
"}\n" +
"],\n" +
"\"reports\": [\n" +
"{\n" +
"\"allowEdit\": true,\n" +
"\"id\": \"48f02....cacc746\"\n" +
"}\n" +
"]\n" +
"}\n";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + accessToken)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
power-bi report embeding in React
import React, { useEffect, useRef, useState } from "react";
import { models } from 'powerbi-client';
const PowerBIEmbed = ({ embedToken }) => {
const powerbiRef = useRef(null);
console.log("embedToken ::: " + embedToken);
useEffect(() => {
const embedPowerBI = async () => {
try {
if (embedToken && powerbiRef.current) {
const embedConfig = {
type: "report",
tokenType: models.TokenType.Embed,
accessToken: embedToken,
embedUrl: "https://app.powerbi.com/reportEmbed?reportId=48f026ea-9....bf48",
id: "48f026....cacc746",
permissions: models.Permissions.All,
viewMode:models.ViewMode.View,
settings: {
panes: {
filters: {
visible: true
},
pageNavigation: {
visible: true
}
},
bars: {
statusBar: {
visible: true
}
}
}
};
window.powerbi.embed(powerbiRef.current, embedConfig);
if (window.powerbi) {
} else {
throw new Error("PowerBI object not found.");
}
} else {
throw new Error("Embed token is not available.");
}
} catch (err) {
console.error("Error embedding Power BI:", err);
}
};
embedPowerBI();
}, [embedToken]);
return <div ref={powerbiRef} />;
};
export default PowerBIEmbed;
React Error message
reportEmbed?reportId=48f026.....acc746&groupId=6a8....48&uid=uexun:549
GET https://api.powerbi.com/metadata/cluster 403 (Forbidden)
Could you clarify why the token format differs from the documentation and provide guidance on how to correctly use it for embedding?
Thank you.
- Anonymous1 year ago
Hi NovaLee
Thank you for reaching out microsoft fabric community forum.The additional @odata.context property in your response is expected in some cases, though not explicitly mentioned in the documentation. The token should be used as-is without extracting any parts, even if it appears concatenated.
The "403 Forbidden" error may be due to an invalid or expired token, insufficient API permissions, incorrect embed configuration, or workspace access issues. Please verify the following:
- Use jwt.io to decode the token and check its expiration (exp).
- Ensure the accessToken used to generate the embed token has Report.ReadWrite.All permission and admin consent.
- Confirm that embedUrl, reportId, and groupId match the intended report.
- Ensure the user embedding the report has access to the workspace.
To further troubleshoot, test embedding via the Power BI Embedding Playground and validate token generation using Postman or another API tool.
I've attached the Microsoft documentation that might be helpful to you.
Generate an embed token in Power BI embedded analytics - Power BI | Microsoft Learn
Troubleshoot Power BI REST APIs - Power BI | Microsoft LearnIf this solution helps, please consider giving us Kudos and accepting it as the solution so that it may assist other members in the community.
Thank you.
4 Replies
- AnonymousNot applicable
Hi NovaLee
Thank you for reaching out microsoft fabric community forum.The additional @odata.context property in your response is expected in some cases, though not explicitly mentioned in the documentation. The token should be used as-is without extracting any parts, even if it appears concatenated.
The "403 Forbidden" error may be due to an invalid or expired token, insufficient API permissions, incorrect embed configuration, or workspace access issues. Please verify the following:
- Use jwt.io to decode the token and check its expiration (exp).
- Ensure the accessToken used to generate the embed token has Report.ReadWrite.All permission and admin consent.
- Confirm that embedUrl, reportId, and groupId match the intended report.
- Ensure the user embedding the report has access to the workspace.
To further troubleshoot, test embedding via the Power BI Embedding Playground and validate token generation using Postman or another API tool.
I've attached the Microsoft documentation that might be helpful to you.
Generate an embed token in Power BI embedded analytics - Power BI | Microsoft Learn
Troubleshoot Power BI REST APIs - Power BI | Microsoft LearnIf this solution helps, please consider giving us Kudos and accepting it as the solution so that it may assist other members in the community.
Thank you. - AnonymousNot applicable
Hi NovaLee
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you. - AnonymousNot applicable
Hi NovaLee
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you. - AnonymousNot applicable
Hi NovaLee
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.