List Gateways Power BI REST API
    • Dark
      Light
    • PDF

    List Gateways Power BI REST API

    • Dark
      Light
    • PDF

    Article Summary

    In a previous Tip, we discussed how we can automate the On-Premises Data Gateway install. Using this process allows for the consistent installation process. Using the PowerShell cmdlets that are discussed in that approach allows us to list gateways, but what if we wanted to have API access to our Gateways? There is a Power BI REST API that allows us to retrieve this data.

    Note: To run the following steps you will need Admin Access

    Within the Power BI Admin portal, we need to ensure that our Tenant settings allow service principals to use Power BI APIs. In addition, you can restrict access to the APIs through security groups.
    1-PBIAdmin

    In addition to the settings that we have just applied in the Power BI Admin experience, we also need to ensure we have a service principal (App registration) in Azure that we can use to access this API. I am leveraging the App registration that was used when using the Power BI Admin PowerShell cmdlets. Please see this video for a complete walkthrough of setting up the service principal.

    Note: For this particular scenario Tenant.Read.All will be sufficient since our API will only read data. Also note that an Admin needs to grant consent.
    2-azure

    With our Power Bi and Azure admin tasks now out of the way, we can build a flow that will call this API. Within our Cloud flow we will use a Schedule trigger and then we will use the HTTP action to call the API. Our URI will be: https://api.powerbi.com/v1.0/myorg/gateways and our Method will be a Get. From an Authentication perspective, we will use Active Directory OAuth. Our Authority will be https://login.windows.net, and our Audience will be https://analysis.windows.net/powerbi/api. The remaining auth settings need to come from our service principal (App registration) from the Azure portal.

    We can subsequently use the Parse Json action so that we can apply a schema to the payload returned from the API.
    3-flow

    Testing

    We can now run our flow and will see a list of Gateways returned to us with a payload that looks like the following:

          "id": "1f69e798-5852-4fdd-ab01-33bb14b6e934",
          "name": "My_Sample_Gateway",
          "type": "Resource",
          "publicKey": {
            "exponent": "AQAB",
            "modulus": "o6j2....cLk="
    
    

    Why don’t I see all my Gateways?

    Within the API docs, it calls out the following: “Returns a list of gateways for which the user is an admin.” Depending upon how you setup your gateways this may be a big issue or it may not be. When we used the PowerShell cmdlets to deploy gateways, we can run it as this same service principal and as a result, this service principal will be an admin of that gateway. As we also discovered when using those PowerShell cmdlets, we can always add our service principal as an admin. By leveraging this approach, we will be able to return all applicable gateways using this API.

    Conclusion

    Gateways are an important component in Power Platform Architecture. As a result, governance becomes quite important. Having visibility to assets is a core part of any governance strategy.


    Was this article helpful?