Forum Discussion
Getting Token for API Dataflow Gateway Binding
- 4 years ago
You are correct, that API call is not exposed. Please vote for the idea.
- 3 years ago
Update
The API works. I've been using the API for over a year to handle automated dataflow gateway binding in various applications.
Rough Outline
To get the access token to use for the API you'll need a couple things to get it through the Microsoft.Identity.Client.
- Get the Application ID from the call by monitor the network traffic while logging into Power BI using the Powershell cmdlets.
- AuthUrl = "https://login.windows.net{tenant identifier}"
- ResourceUrl ="https://analysis.windows.net/powerbi/api'
Run API
- Add an AuthenticationHeader to a HttpClient containing the access token.
- Get the URL Base API path from monitoring network traffic when binding a dataflow to a gateway in PBI Online
- URL will be "{Url base path}/metadata/dataflows/settings/{dataflow.ObjectId}/bind"
- Content will be a json formatted string with Gateway ID
- "{{""gatewayObjectId"":""{gateway.Id}""}}"
- Post
I should note that I created a .NET app that manages various aspects of Power BI. I'm using the token from Get-PowerBIAccessToken Powershell cmdlet, using my credentials, to run the dataflow gateway binding API. It works fine for me. If another user uses the gateway binding functionality for dataflows that they cloned, it doesn't work, presumibly because the token is for my user and the dataflow owner is the app user.
My goal is to ditch the Powershell script and move the token generation into the application so any user can use the "hidden" Power BI REST API.