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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ViralGajjar2904
Frequent Visitor

Refresh API getting wrong data

I published below report in powerbi server by updating latest SessionId & BaseURL based on Client's interaction from webpage.

 

let
    body="{""sessionId"": """& SessionIDPara &""",
    ""isSearch"": false,
    ""keyword"": """",
    ""exploreType"": 2}",
    Source=Json.Document(Web.Contents(BaseURLPara,
[
RelativePath="/testAPI/explorer/location_hierarchy",
Content=Text.ToBinary(body),
                Headers=[#"Content-Type"="application/json"]
        ])),
    #"Converted to Table" = Record.ToTable(Source),
    Value = #"Converted to Table"{1}[Value],
    #"Converted to Table1" = Record.ToTable(Value),
    Value1 = #"Converted to Table1"{0}[Value],
    #"Parsed JSON" = Json.Document(Value1),
    #"Converted to Table2" = Record.ToTable(#"Parsed JSON"),
    #"Expanded Value" = Table.ExpandListColumn(#"Converted to Table2", "Value"),
    #"Expanded Value1" = Table.ExpandRecordColumn(#"Expanded Value", "Value", {"EntID", "EntityName", "Name", "Description", "Type", "Icon", "Room"}, {"EntID", "EntityName", "Name.1", "Description", "Type", "Icon", "Room"}),
    #"Expanded Room" = Table.ExpandListColumn(#"Expanded Value1", "Room"),
    #"Expanded Room1" = Table.ExpandRecordColumn(#"Expanded Room", "Room", {"EntID", "EntityName", "Name", "Description", "Type", "Icon", "Floor"}, {"EntID.1", "EntityName.1", "Name.2", "Description.1", "Type.1", "Icon.1", "Floor"}),
    #"Expanded Floor" = Table.ExpandListColumn(#"Expanded Room1", "Floor"),
    #"Expanded Floor1" = Table.ExpandRecordColumn(#"Expanded Floor", "Floor", {"EntID", "EntityName", "Name", "Description", "Type", "Icon", "HasChildren"}, {"EntID.2", "EntityName.2", "Name.3", "Description.2", "Type.2", "Icon.2", "HasChildren"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Expanded Floor1",{{"EntID", "Parent ID"}, {"Name.1", "Site Name"}, {"Type", "Room Type"}, {"Name.2", "Room Name"}, {"Name.3", "Floor Name"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns1",{"Description", "Icon", "Description.1", "Icon.1", "Description.2", "Icon.2"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([EntID.1] <> null))
in
    #"Filtered Rows"
 
I have two urls for testing purpose.
1) n20a.netzoom.com
2) 20.netzoom.com
 
when I open n20a.netzoom.com & try to access powerbi report, then BaseURL & Sessionid will be fetched from webpage dynamically & update parameter & refresh API will be call.Refresh take 10 seconds to complete.In between above process when i open 20.netzoom.com the BaseURL & Sessionid will be fetched from its webpage dynamically & parameter update.
But after completed first user's (n20a.netzoom.com) refresh API I am getting data of second user(20.netzoom.com)
 
I don't know why this is happen...I embed report using embed token, still I am not getting actual data.
 
Can anybody know this issue & how to solve it?
1 ACCEPTED 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

 

 

View solution in original post

3 REPLIES 3
hackcrr
Super User
Super User

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

 

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors