Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

403 When I try to get Datasets via POWERBI Service

Hi All,

 

I am currently working on PowerBI integration. I have set-up an application and granted access to the PowerBI Service APIs.

 

But after getting the access token, I get a 403 when I try to call https://api.powerbi.com/v1.0/myorg/datasets

 

Here is my sample code:

 

String datasetJson = "{\"name\": \"Sales101\", \"tables\": " +
"[{\"name\": \"Product\", \"columns\": " +
"[{ \"name\": \"ProductID\", \"dataType\": \"Int64\"}, " +
"{ \"name\": \"Name\", \"dataType\": \"string\"}, " +
"{ \"name\": \"Category\", \"dataType\": \"string\"}," +
"{ \"name\": \"IsCompete\", \"dataType\": \"bool\"}," +
"{ \"name\": \"ManufacturedOn\", \"dataType\": \"DateTime\"}" +
"]}]}";


OkHttpClient client = new OkHttpClient.Builder()
.followRedirects(false)
.build();
RequestBody formBody = RequestBody.create(MediaType.parse("application/json"), datasetJson);

Request request = new Request.Builder().addHeader("Authorization", String.format("Bearer {0}", accessToken))
.url("https://api.powerbi.com/v1.0/myorg/datasets")
.post(formBody)
.build();

Call call = client.newCall(request);
okhttp3.Response response = call.execute();

 

Please note that my access token seem to have the right permissions. Please see below excerpt when I decoded my JWT:

 

"scp": "App.Read.All Capacity.Read.All Capacity.ReadWrite.All Content.Create Dashboard.Read.All Dashboard.ReadWrite.All Dataflow.Read.All Dataflow.ReadWrite.All Dataset.Read.All Dataset.ReadWrite.All Gateway.Read.All Gateway.ReadWrite.All Report.Read.All Report.ReadWrite.All StorageAccount.Read.All StorageAccount.ReadWrite.All Tenant.Read.All Tenant.ReadWrite.All Workspace.Read.All Workspace.ReadWrite.All",

 

 

Also, please note that I am a normal PowerBI user. To use the APIs.. . I did the following:

 

- Created a new app with client Id and Secret

- Set-up the right permissions for APIs

 

I didn't do any changes on PowerBI... I assume the API permissions are enough?

 

Guidance is extremely appreciated.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

this is resolved. The problem was with the String.format function I was using. The token wasn't being passed.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

this is resolved. The problem was with the String.format function I was using. The token wasn't being passed.

lbendlin
Super User
Super User

What happens when you do a dry run on the API website?

 

https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/getdatasets

click the "try it"  button.

Anonymous
Not applicable

Hi @lbendlin The dry run works and I am able to push the dataset. But, I think the Try button uses a predefined cllient and impersonator scope. I am not sure what is it that I am doing wrong

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors