Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I published below report in powerbi server by updating latest SessionId & BaseURL based on Client's interaction from webpage.
Solved! Go to Solution.
Hi, @ViralGajjar2904
Here is a sample API call to generate an embed token:
import requests
import json
def generate_embed_token(username, report_id, dataset_id, workspace_id):
url = "https://api.powerbi.com/v1.0/myorg/reports/{report_id}/GenerateToken"
payload = json.dumps({
"accessLevel": "View",
"identities": [
{
"username": username,
"roles": ["Viewer"],
"datasets": [dataset_id]
}
]
})
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
}
response = requests.request("POST", url.format(report_id=report_id), headers=headers, data=payload)
if response.status_code == 200:
return response.json()['token']
else:
raise Exception(f"Error generating embed token: {response.text}")
# Example usage:
embed_token = generate_embed_token("user@example.com", "report_id", "dataset_id", "workspace_id")
Ensure that your embedded report uses the token generated for the specific user session. This can be done in your client-side code where the Power BI report is embedded:
var embedToken = 'USER_SPECIFIC_EMBED_TOKEN';
var reportId = 'YOUR_REPORT_ID';
var groupId = 'YOUR_GROUP_ID';
var embedUrl = `https://app.powerbi.com/reportEmbed?reportId=${reportId}&groupId=${groupId}`;
var models = window['powerbi-client'].models;
var embedConfig = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: embedToken,
embedUrl: embedUrl,
id: reportId,
permissions: models.Permissions.All,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: true
}
};
// Embed the report and display it within the div container.
var reportContainer = document.getElementById('reportContainer');
var report = powerbi.embed(reportContainer, embedConfig);
Use different browser sessions or incognito windows to simulate multiple users accessing the report. Ensure that each session generates and uses a unique embed token.
If this post helps, then please consider Accept it as the solution and kudos to this post to help the other members find it more quickly
Hi, @ViralGajjar2904
The main reason for this problem is that power BI caches parameters and provides the latest values. When you open two websites, the two refresh operations are very close and there is a progress bar, which will cause the report to pick up parameters from the last trigger.
You can consider: generating a new token for each session to ensure that the data is isolated.
If this post helps, then please consider Accept it as the solution and kudos to this post to help the other members find it more quickly
Hi @hackcrr
should I have to generate unique embed token for user wise?
I already configured code for generate embed token, but I do not have multi users for testing purpose.
I am aceessing reports form both websites (n20.netzoom.com & 20.netzoom.com) via Single user, so it might be cretae above problem? I am not sure...!
Could you please suggets how to use embed token once generated.
Hi, @ViralGajjar2904
Here is a sample API call to generate an embed token:
import requests
import json
def generate_embed_token(username, report_id, dataset_id, workspace_id):
url = "https://api.powerbi.com/v1.0/myorg/reports/{report_id}/GenerateToken"
payload = json.dumps({
"accessLevel": "View",
"identities": [
{
"username": username,
"roles": ["Viewer"],
"datasets": [dataset_id]
}
]
})
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
}
response = requests.request("POST", url.format(report_id=report_id), headers=headers, data=payload)
if response.status_code == 200:
return response.json()['token']
else:
raise Exception(f"Error generating embed token: {response.text}")
# Example usage:
embed_token = generate_embed_token("user@example.com", "report_id", "dataset_id", "workspace_id")
Ensure that your embedded report uses the token generated for the specific user session. This can be done in your client-side code where the Power BI report is embedded:
var embedToken = 'USER_SPECIFIC_EMBED_TOKEN';
var reportId = 'YOUR_REPORT_ID';
var groupId = 'YOUR_GROUP_ID';
var embedUrl = `https://app.powerbi.com/reportEmbed?reportId=${reportId}&groupId=${groupId}`;
var models = window['powerbi-client'].models;
var embedConfig = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: embedToken,
embedUrl: embedUrl,
id: reportId,
permissions: models.Permissions.All,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: true
}
};
// Embed the report and display it within the div container.
var reportContainer = document.getElementById('reportContainer');
var report = powerbi.embed(reportContainer, embedConfig);
Use different browser sessions or incognito windows to simulate multiple users accessing the report. Ensure that each session generates and uses a unique embed token.
If this post helps, then please consider Accept it as the solution and kudos to this post to help the other members find it more quickly
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.