Skip to content

m-moris/PowerBI-SDK-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Power BI Embedded SDK for Java

It is sample of translation from PowerBI-Csharp. I belive that Microsoft will be officially released in the near future :-)

Generate Token

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

<dependency>
	<groupId>io.jsonwebtoken</groupId>
	<artifactId>jjwt</artifactId>
	<version>0.7.0</version>
</dependency>

REST Client

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.

Sample

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());
			}
		}				

How to generate

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

AutoRest

You can get AutoRest Chocolately.

Dependency

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>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published