Forum Discussion

cporteous's avatar
cporteous
Most Valuable Professional
8 years ago
Solved

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

  • izurev's avatar
    izurev
    8 years ago

    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.

     

     

9 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft 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).

     

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

  • izurev's avatar
    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

    • cporteous's avatar
      cporteous
      Most Valuable Professional

      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

      • izurev's avatar
        izurev
        Frequent Visitor

        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.