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

Power BI REST API

Hi everyone , I'm trying to get all the datasources for my organization.I'm using a service principal to connect to Power BI Service.
I made a function with PowerShell where I have made a this loop to get all the datasetId.


$OrgWorkspaces = Get-PowerBIDataset -Scope Organization
foreach ( $OrgWorkspace in $OrgWorkspaces)
{
$DatasetId= $($OrgWorkspace.Id)
# Write-Host $DatasetId

}


And this worked But when I added this line of code
$DataSources = Get-PowerBIDatasource -DatasetId $DatasetId
into the loop It didn't work ! I tried to put a DatasetId from the list I had
$DataSources = Get-PowerBIDatasource -DatasetId 1505150a-36f2-408e-a1e7-3531e6e0fccf *** but I have this error:
[Error] ERROR: Operation returned an invalid status code 'Forbidden'Exception :Type : Microsoft.Rest.HttpOperationExceptionRequest :Method : GETRequestUri : https://api.powerbi.com/v1.0/myorg/datasets/1505150a-36f2-408e-a1e7-3531e6e0fccf/datasourcesHeaders :Authorization : …User-Agent : MicrosoftPowerBIMgmt/1.2.0.0Response :StatusCode : ForbiddenReasonPhrase : ForbiddenContent : {"Message":"API is not accessible for application".

Any idea of this error please?

2 ACCEPTED SOLUTIONS
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

According to the error message, it seems that you do not have the appropriate permission to view the data source information of this data set. Please confirm whether to Enable service principal authentication for read-only admin APIs and check whether to add the service principal as a member or admin to your workspace. Change your cmdlet scripts as below and check whether it can work well, you can refer the content in this blog: POWER BI ADMIN DATASETS

Note: Please make sure the dataset id is correct.

$DataSources = Get-PowerBIDatasource -DatasetId 1505150a-36f2-408e-a1e7-3531e6e0fccf ***  -Scope Organization

In addition, please review the following rest API and check whether it can get your desired result.

Admin - Datasets GetDatasourcesAsAdmin

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Thank you for your answer!

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

According to the error message, it seems that you do not have the appropriate permission to view the data source information of this data set. Please confirm whether to Enable service principal authentication for read-only admin APIs and check whether to add the service principal as a member or admin to your workspace. Change your cmdlet scripts as below and check whether it can work well, you can refer the content in this blog: POWER BI ADMIN DATASETS

Note: Please make sure the dataset id is correct.

$DataSources = Get-PowerBIDatasource -DatasetId 1505150a-36f2-408e-a1e7-3531e6e0fccf ***  -Scope Organization

In addition, please review the following rest API and check whether it can get your desired result.

Admin - Datasets GetDatasourcesAsAdmin

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you for your answer!

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.