It is sample of translation from PowerBI-Csharp. I belive that Microsoft will be officially released in the near future :-)
Use following code.
String workspacename = "<<your-workspace-name>>";
String username = "<<username>>";
String workspaceId = "<<workspace id>>";
String reportId = "<<reportid>>";
String accessKey = "<<your access key from portal >>"
PowerBIToken token = PowerBIToken.CreateReportEmbedToken(
workspacename,
workspaceId,
reportId,
username,
null);
String jwt = powerbitoken.Generate(accessKey);
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
REST Clients was generated by AutoRest from swagger.json. C# SDK uses AutoRest version 1.6, Java also uses same version.
Generate code is usually not changed, but they does not work properly, so I fixed PowerBIClient.java.
This sample is retrive all workspaces and report from workspace collection.
String key = "<<your access key>>";
TokenCredentials creds = new TokenCredentials("AppKey", key);
PowerBIClient client = new PowerBIClientImpl(creds);
ServiceResponse<ODataResponseListWorkspace> workspaces = client.getWorkspacesOperations()
.getWorkspacesByCollectionName("<<collection name>>");
for (Workspace ws : workspaces.getBody().getValue()) {
System.out.printf("%s\n", ws.getWorkspaceId());
ServiceResponse<ODataResponseListReport> reports = client.getReportsOperations().getReports(collectionName,
ws.getWorkspaceId());
for (Report report : reports.getBody().getValue()) {
System.out.printf(" %s\t%s\t%s\t%s\n", report.getName(), report.getId(), report.getEmbedUrl(), report.getWebUrl());
}
}
You can execute generate.bat.
AutoRest.exe -CodeGenerator Java -Modeler Swagger -Input swagger.json
-Namespace microsoft.powerbi.api.v1 -output src\main\java\ -name PowerBIClient -AddCredentials
You can get AutoRest Chocolately.
Auto generator code require client runtime library.
<dependency>
<groupId>com.microsoft.rest</groupId>
<artifactId>client-runtime</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
...
...
<repository>
<id>adx-snapshots</id>
<name>Azure ADX Snapshots</name>
<url>http://adxsnapshots.azurewebsites.net/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>