I need to embed a report that receives two parameters: ‘iddefinicionentorno’ and ‘idperfil’. Supposedly, the report should change based on these parameters, but I’m not getting results with any method I’ve tried. This is my code:
The Thymeleaf template (HTML):
<head>
<title>Power BI Report</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/powerbi-client/2.23.1/powerbi.js"></script>
</head>
<body>
<div id="reportContainer" style="height: 100vh; border: 5px solid #ccc;"></div>
<script th:inline="javascript">
var accessToken = [[${accessToken}]];
var embedUrl = [[${embedUrl}]];
var embedId = [[${embedId}]];
let models = window['powerbi-client'].models;
console.log(accessToken);
let embedConfiguration = {
accessToken: accessToken,
embedUrl: embedUrl,
id: embedId,
permissions: 0,
tokenType: 1,
type: 'report',
settings:{
}
};
// Get a reference to the HTML element that contains the embedded report.
let embedContainer = document.getElementById('reportContainer');
// Embed the report.
let report = powerbi.embed(embedContainer, embedConfiguration);
embed.render().then(function(event) {
// Report loaded successfully
}).catch(function(error) {
console.error("Error embedding report:", error);
});
</script>
The Controller in Spring Boot:
@RequestMapping("/testAnalitica")
public String testAnalitica(Model model) {
String token = powerBIService.getToken();
String[] embedUrl = powerBIService.getEmbed(token);
String newToken = powerBIService.getEmbedToken(token);
model.addAttribute("accessToken", newToken);
model.addAttribute("embedUrl", embedUrl[0]);
model.addAttribute("embedId", embedUrl[1]);
return "analiticageneraltest";
}
The service that gets the embedUrl
String reportEndpointWithParams = reportEndpoint + "?iddefinicionentorno=" + 3 + "&idperfil=" + 3;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(reportEndpointWithParams))
.header("Media-Type", "")
.header("Authorization", "Bearer " + token)
.GET()
.build();
try {
java.net.http.HttpResponse<String> response = httpClient.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
JSONObject jsonObject = new JSONObject(response.body());
String embed = jsonObject.getString("embedUrl");
String id = jsonObject.getString("id");
return new String[]{embed, id};
} else {
System.err.println("Error al obtener el embed. Código de estado: " + response.statusCode());
return null;
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
return null;
}
I need the report to change based on those parameters. Take into account that I’m only the developer. According to the Analyst who made the report, it should be working fine with the parameters. I’ve tried adding the parameters to the endpoint with different syntax like rp:parameterName
and Parametro_parametername
and the one in the code I’ve pasted above, but none of them work.