March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I get an Error 400 (Bad Request) using the code below. I have looked at it for hours. Does anyone see anything wrong? Any suggestions?
#Login to Power BI using PowerBIPS App registration.
Write-Host "Start Login"
$ApplicationId = "abc123"
$SecurePassword = "password" | ConvertTo-SecureString -AsPlainText -force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationId, $SecurePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "ten123"
Write-Host "Login Success"
Write-Host "Get Workspace info for workspace: AC Common_TST"
$workspaceName = "AC Common_TST"
$datasetName = "DateDim"
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$workspaceObject = ( Get-PowerBIWorkspace -Name "AC Common_TST" )
$groupid=$workspaceObject.id
$newGatewayId = "gatewayid" # the ID of PRDGateway1
$dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id | Where-Object Name -eq $datasetName
$datasetid = $dataset.id
$workspaceId = $workspace.Id
Write-Host "GroupID is "$workspace.id
Write-Host "Dataset ID is "$dataset.id
# POST body
$postParams = @'
{
"gatewayObjectId": "gatewayid",
"datasourceObjectIds": [
"dsid"
]
}
'@
$jsonPostBody = $postParams | ConvertTo-JSON
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$workspaceid/datasets/$datasetId/Default.BindToGateway"
Invoke-PowerBIRestMethod -URL $uri -Method POST -Body $jsonPostBody
Resolve-PowerBIError -Last
Hi @bmtolleson ,
The following ones are the threads which have the similar problem as yours, please check their solution. Hope they can also help solve your problem.
BindToGateway Powershell REST API POST failing
I have found the reasons why this wasnt working so thought I would list them here for future users. To get this to work there are a few things to be aware of:
1. If the datasource is not assigned to a gateway you need to not include the datasource ID values (you wont actually be able to get these ID values if it is unassigned). I assume the ability to specify the data source id values is only relevent when the dataset is already assigned to a gateway, but I dont know if you can use two separate gateways for one dataset with two datasources.
2. Service principals cant be set to administrators of gateways, so you cant use them
3. Users must be set as administrators of gateways
4. The user must be assigned as a user of the data source defined on the gateway (different from being a gateway admin)
Getting Token for API Dataflow Gateway Binding
Best Regards
I tried the suggestions in that post, but no luck.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
8 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
10 | |
3 | |
2 | |
2 | |
2 |