Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I am implementing an "Embed for your customers" environment, using Service Principle profiles to interact with reports, etc.
I'm trying to automate as much of the process as possible, using Powershell scripts to call the Power BI Rest API.
I have an On-Premise Data Gateway, which contains an SQL datasource.
I have scripts that will create a workspace for a profile, and upload a report into that workspace. I am then attempting to bind the newly created dataset to the Gateway's datasource. I'm calling the Bind To Gateway In Group endpoint to do that, and getting a 200 Success response, but when I lok at the dataset details, they haven't changed. The dataset seemingly already has values for "gatewayId" and "datasourceId" when newly uploaded, and those details aren't changed by the "Bind to Gateway" operation. I'll include script and output below.
Additional info:
* the service principal I'm using to call the API endpoint is already configured as a user of the gateway data source.
Script which call the Bind To Gateway In Group endpoint:
# get access token for power bi rest api calls
$accessToken = & "$PSScriptRoot\Obtain-AAD-Access-Token.ps1"
$powerBIProfileRequestHeaders = @{
Authorization = "Bearer $($accessToken)"
"X-PowerBI-Profile-Id" = $profileId
}
Write-Host "------------------------
Dataset Datasources Details"
$datasetDataSourcesResponse = Invoke-WebRequest "https://api.powerbi.com/v1.0/myorg/groups/$($workspaceId)/datasets/$($datasetId)/datasources" -Method "GET" -UseBasicParsing -Headers $powerBIProfileRequestHeaders
Write-Host $datasetDataSourcesResponse
Write-Host "------------------------
Gateway Bind Response"
$gatewayBindRequestBody = '{"gatewayObjectId": "' + $gatewayId + '","datasourceObjectIds": ["' + $datasourceId +'"]}'
$bindResponse = Invoke-WebRequest "https://api.powerbi.com/v1.0/myorg/groups/$($workspaceId)/datasets/$($datasetId)/Default.BindToGateway" -ContentType "application/json" -Method "POST" -Body $gatewayBindRequestBody -UseBasicParsing -Headers $powerBIProfileRequestHeaders
Write-Host $bindResponse
Write-Host "------------------------
Dataset Datasources Details"
$datasetDataSourcesResponse = Invoke-WebRequest "https://api.powerbi.com/v1.0/myorg/groups/$($workspaceId)/datasets/$($datasetId)/datasources" -Method "GET" -UseBasicParsing -Headers $powerBIProfileRequestHeaders
Write-Host $datasetDataSourcesResponse
Output from that script:
PS C:\Code\PowerBIEmbedded\Powershell> .\Bind-Dataset-To-Gateway-Datasource.ps1 -profileId 842a0625-2dc8-4bd1-9ebb-b19d000e4890 -workspaceId ffabeae1-ae0e-42fe-bc69-a4a37723358d -datasetId 3ab75fc2-f70f-4578-8827-517c3a538122 -gatewayId 1fd4ac45-485f-45e0-9f1a-1abc3a938214 -datasourceId 2928f90b-10a2-47fe-a0a7-8745758d19a7
------------------------
Dataset Datasources Details
{
"@odata.context":"http://wabi-north-europe-i-primary-redirect.analysis.windows.net/v1.0/myorg/groups/ffabeae1-ae0e-42fe-bc69-a4a37723358d/$metadata#datasources","value":[
{
"datasourceType":"Sql","connectionDetails":{
"server":"xxxxxxx","database":"xxxxxxx"
},"datasourceId":"5e441ef8-6af9-4e57-8de1-41cabfe0a9a9","gatewayId":"36baeaf5-e58a-4d91-8ba1-6be83a5cb547"
}
]
}
------------------------
Gateway Bind Response
------------------------
Dataset Datasources Details
{
"@odata.context":"http://wabi-north-europe-i-primary-redirect.analysis.windows.net/v1.0/myorg/groups/ffabeae1-ae0e-42fe-bc69-a4a37723358d/$metadata#datasources","value":[
{
"datasourceType":"Sql","connectionDetails":{
"server":"xxxxxxx","database":"xxxxxxx"
},"datasourceId":"5e441ef8-6af9-4e57-8de1-41cabfe0a9a9","gatewayId":"36baeaf5-e58a-4d91-8ba1-6be83a5cb547"
}
]
}
Can anyone help?
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 56 | |
| 56 | |
| 35 | |
| 18 | |
| 14 |