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

Gateway info from Power BI API in PowerShell

Hi,

 

So Ive got all manner of data out of the Power BI REST API using PowerShell, using both a Native & Web app.

 

Im trying to hit this API and getting a 401 across the board though I got it working a few weeks back strangely...

 

https://api.powerbi.com/v1.0/myorg/gateways

 

The user is an admin on all of my data Gateways & the apps have all the perms in Power BI.

 

Is there a template example someone could provide, where this just works or any ideas? Its obviously auth but I dont see what Id need to alter (or even how I got some of it working a few weeks back).

 

Here's the script Im using...

 

https://github.com/cporteou/Powershell_PowerBI/blob/master/PowerBI_API_Gateway.ps1

 

Thanks

1 ACCEPTED SOLUTION

Login to Azure portal with the user that you use for the API requests and navigate to the APP and then click on Required permissions and then click Grant Permissions. This will assign all permissions to that user (11 permissions for Power BI Service). That solved the issue for me.

 

You may also need to generate a new login token for the user after that...

 

Let me know if that worked for you.

 

 

View solution in original post

9 REPLIES 9
izurev
Frequent Visitor

how was this solved?

I'm having the same issue - seeing 401 error when querying for the gateways using the Power BI API - other endpoints are working fine.

Also, checked and i see all 11 delegated permissions on the App side.

 

Thanks in advance,

Alex

I still don't have this solved.

 

The app can query all other aspects of Power BI through the API but always returns a 401 for Gateway calls

Login to Azure portal with the user that you use for the API requests and navigate to the APP and then click on Required permissions and then click Grant Permissions. This will assign all permissions to that user (11 permissions for Power BI Service). That solved the issue for me.

 

You may also need to generate a new login token for the user after that...

 

Let me know if that worked for you.

 

 

That's it. I needed to force the prompt for login. Refreshing the token alone didn't fix it. It looks like I needed to just Grant Permissions from within Azure. Its weird as I tried this months ago with no success. May have been a localised issue to my tenant or some other permissions problem.

 
Thanks! It's always the little things eh!

I find all these "settings" not very intuitive... 

Glad to know that this is working for you now 🙂

 

Cheers,

Alex

 

Tried that.

 

The app has 13 permissions too.

 

Did you create FROM Power BI or from Azure?

Created the app from Azure as Native.

Also, you might also want to try to generate the token using prompt - to input the user/password again - maybe it will also prompt you for the new permissions (make sure that neither of the selected permissions need Admin).

And check that the user is set as Admin on the Power BI Portal side for at least one Gateway.

Eric_Zhang
Employee
Employee


@cporteous wrote:

Hi,

 

So Ive got all manner of data out of the Power BI REST API using PowerShell, using both a Native & Web app.

 

Im trying to hit this API and getting a 401 across the board though I got it working a few weeks back strangely...

 

https://api.powerbi.com/v1.0/myorg/gateways

 

The user is an admin on all of my data Gateways & the apps have all the perms in Power BI.

 

Is there a template example someone could provide, where this just works or any ideas? Its obviously auth but I dont see what Id need to alter (or even how I got some of it working a few weeks back).

 

Here's the script Im using...

 

https://github.com/cporteou/Powershell_PowerBI/blob/master/PowerBI_API_Gateway.ps1

 

Thanks


@cporteous

The Power scripts appears good. As to the 401 error, in Azure portal, please ensure the registered Azure AD APP to which the client_id and client_secret belong has sufficient permission. The Power BI service has all delegated perssions(11).

Capture.PNG

Capture (1).PNG

 

Before in PowerShell, you could also try to hit that REST API in POSTMAN.

Hi Eric,

 

Thanks for the response.

 

Ill try POSTMAN. The app was created from https://dev.powerbi.com/apps and it has all 11 delegated permissions for PowerBI.

 

Ta

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.