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.

0

Power BI REST API - Datasets GetDatasourcesAsAdmin 401 despite Tenant.ReadWrite.All

Hi, we have an Azure AD user who has the PowerBI Admin rights. The "scp" of the bearer token is:

"scp": "App.Read.All Capacity.ReadWrite.All Dashboard.ReadWrite.All Dataflow.ReadWrite.All Dataset.ReadWrite.All Group.Read.All Metadata.View_Any Report.ReadWrite.All StorageAccount.ReadWrite.All Tenant.ReadWrite.All Workspace.ReadWrite.All"

I need to get the Tables of a Dataset. Since there is no direct connection (when running with the .NET Sdk, the "Tables" property is always empty) I thought I could get the Datasource and connect to it.

However, when I try to do it like here: https://docs.microsoft.com/en-us/rest/api/power-bi/admin/datasets-get-datasources-as-admin

I always get a 401 when trying to get the datasource for a dataset like this:

https://api.powerbi.com/v1.0/myorg/admin/datasets/cfafbeb1-8037-4d0c-896e-a46fb27ff229/datasources

When just requesting the dataset via:

https://api.powerbi.com/v1.0/myorg/admin/datasets/cfafbeb1-8037-4d0c-896e-a46fb27ff229

it works and gets me the dataset back.

Any suggestions, why I get a 401 here?

Status: Delivered

Hi @nsoeth ,

 

According to the test, no matter whether you add the /datasources to the REST API URL, it will run successfully as well. And the difference is you will get metadata of this dataset if you don’t add /datasources. Conversely, you will get datasource info of the dataset if /datasources has been added to the URL.

vcazhengmsft_0-1648087892986.png

 

vcazhengmsft_1-1648087892988.png

 

For the 401 Unauthorized error, it represents a client-side error, which means that the request sent was not fulfilled due to lack of authentication credentials required by the target resource. To run this REST API, you need these permissions and required scope.

vcazhengmsft_2-1648087892990.png

 

For you have required scope and administrator rights, and you could run this API when removing /datasource. This issue should not be caused by permissions, it’s more caused by the configurations of your app and the code in it. You can consider restart your app and try again and check the configuration and code.

 

Best Regards,

Community Support Team _ Caiyun

Comments
v-cazheng-msft
Community Support
Status changed to: Delivered

Hi @nsoeth ,

 

According to the test, no matter whether you add the /datasources to the REST API URL, it will run successfully as well. And the difference is you will get metadata of this dataset if you don’t add /datasources. Conversely, you will get datasource info of the dataset if /datasources has been added to the URL.

vcazhengmsft_0-1648087892986.png

 

vcazhengmsft_1-1648087892988.png

 

For the 401 Unauthorized error, it represents a client-side error, which means that the request sent was not fulfilled due to lack of authentication credentials required by the target resource. To run this REST API, you need these permissions and required scope.

vcazhengmsft_2-1648087892990.png

 

For you have required scope and administrator rights, and you could run this API when removing /datasource. This issue should not be caused by permissions, it’s more caused by the configurations of your app and the code in it. You can consider restart your app and try again and check the configuration and code.

 

Best Regards,

Community Support Team _ Caiyun

nsoeth
Regular Visitor

Hi,

 

thanks a lot for the quick response. 

 

I am in the early stages so I am just trying to get the data with postman and even there it fails.

 

The permissions should be fine as permissions and scope (according to the documentation) are the same for both requests, just as you said. Just to make sure, I get the access token via the following request:

nsoeth_0-1648105998085.png

I "anonymized" our tenant url, client id and refresh token obviously.

 

Is there already an error here?