Forum Discussion
How to pass parameter in Datasets - Update Parameters from C#
Hi,
i am embed the powerbi repoert in C# web application and working fine.
now i want to send some parameters like seesion id etc in Default.UpdateParameters.
how to configure and send the parameters from C#.
and when i need to call this api (Datasets - Update Parameters - REST API (Power BI Power BI REST APIs))
after getting the token or call after javascript code like
const config = {
type: 'report',
/* tokenType: models.TokenType.Embed,*/
tokenType: 1,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedReportId,
/* permissions: models.Permissions.All,*/
permissions: 7,
settings: {
// Enable this setting to remove gray shoulders from embedded report
// background: models.BackgroundType.Transparent,
filterPaneEnabled: false,
navContentPaneEnabled: false,
}
};
please provide some solution.
1 Reply
- Bipin-LalaSolution Sage
Hi anant,
You must execute the UpdateParameters API call on your C# backend before you generate the Embed Token and pass the configuration to your JavaScript front end.
The Workflow Sequence:
- User requests report: Your C# application captures the context (e.g., Session ID, User Info).
- Backend API Call: Your C# code calls the Power BI REST API (Default.UpdateParameters) to update the parameter inside the dataset model.
- Trigger Dataset Refresh (If Import Modeπ If your dataset is in Import Mode, you must trigger a refresh for the changes to apply. If your model uses DirectQuery, the parameter update is effective instantly.
- Generate Embed Token: Your C# code requests the Embed Token from Power BI.
- Front-End Render: Pass the token, embed URL, and Report ID to your JavaScript frontend configuration object. The visual will render with the new parameter data automatically applied.
If you are using the official Microsoft.PowerBI.Api NuGet package, you can leverage the strongly typed wrappers to execute this call cleanly. If you prefer raw JSON execution, a standard HttpClient POST request will do the trick.
using Microsoft.PowerBI.Api; using Microsoft.PowerBI.Api.Models; public async Task UpdatePowerBIParameters(PowerBIClient pbiClient, Guid workspaceId, Guid datasetId, string sessionId) { // Define the specific parameter you want to change var parameterDetails = new UpdateMashupParameterDetails { Name = "SessionIDParam", // Must exactly match the parameter name in Power Query NewValue = sessionId }; // Construct the request wrapper var updateRequest = new UpdateMashupParametersRequest { UpdateDetails = new List<UpdateMashupParameterDetails> { parameterDetails } }; // Execute the POST request to the XMLA target group await pbiClient.Datasets.UpdateParametersInGroupAsync(workspaceId, datasetId, updateRequest); }There are a few more considerations regarding parameter data type that you might have to look into.
Let me know if this helps or if you need more info!