Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I need to create an application that will allow you to register multiple users and link them to your Power BI account. In this application I will attach a .pbix file and I will replicate for all users.
I created an app on azure to be able to access the Power BI development APIs.
To do a test, I'm trying to call the groups API, when I run it directly in the documentation it works. Copying the token (Authorization) that it displays in the documentation and defining it in the request header in my app works too. However, when I try to generate a token it doesn't work.
Can anyone tell me what I'm doing wrong? What if what I want to do is possible?
@RestController
@RequestMapping("/group")
public class GroupsController {
@GetMapping
public String getGroups() throws Exception {
var token = GetAccessToken();
var rest = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
var authorization = "Bearer " + token;
headers.set("Authorization", authorization);
var result = rest.exchange("https://api.powerbi.com/v1.0/myorg/groups", HttpMethod.GET, new HttpEntity(headers), String.class);
return result.getBody();
}
private String GetAccessToken() throws Exception {
AuthenticationContext authenticationContext = new AuthenticationContext(
"https://login.windows.net/common/oauth2/authorize",
false,
Executors.newSingleThreadExecutor()
);
var authenticationResult = authenticationContext.acquireToken(
"https://analysis.windows.net/powerbi/api",
new ClientCredential(CLIENT_ID, CLIENT_SECRET),
null
).get();
return authenticationResult.getAccessToken();
}
}
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
1 | |
1 | |
1 | |
1 |
User | Count |
---|---|
26 | |
3 | |
2 | |
2 | |
2 |