Forum Discussion
How to add cloud connection and bind it after to dataset programatically/via rest API
Hi Guys,
I want to add cloud connection (to the blob storage) to the power bi service and as next step i want to bind it with currect existing dataset.
How to do this programatically?
Current solution which I found are related with connecting to on-promises data source (existing ones).
https://www.youtube.com/watch?v=lfP6ygindSU&list=PLpBU4EcPajILyeFik6p9EedYoUH4kh12m&index=8
Best,
Jacek
Hi. The bind is only for Gateway. After you configure a gateway and a source you can set a source to the dataset. But, if you are connecting to cloud sources that's not an option. The most similar thing I have seen at the Fabric Rest API (it's kind of new), it's updating connection. It let's you change the connection and credentials of a dataset. I'm not sure how the body is built, it's really new and I haven't tried it yet. You can read about it here: https://learn.microsoft.com/en-us/rest/api/fabric/core/connections/update-connection?tabs=HTTP
I don't think there is another way.
I hope that helps,
3 Replies
- aakhpggmNew Member
To bind to a cloud data source you can provide 00000000-0000-0000-0000-000000000000 as the gateway ID for the bind to gateway API. Found this in an example for the FabricPS-PBIP powershell module (source).
Sample - Deploy semantic model and bind to Shared Cloud Connection (SCC)
$workspaceName = "[Workspace Name]" $pbipPath = "[PBIP Path]\[Name].SemanticModel" $connectionsToBind = @("[SCC Connection Id]") # Authenticate Set-FabricAuthToken -reset # Ensure workspace exists $workspaceId = New-FabricWorkspace -name $workspaceName -skipErrorIfExists # Import the semantic model and save the item id $semanticModelImport = Import-FabricItem -workspaceId $workspaceId -path $pbipPath # Bind to connections using PowerBI API - no need to specify the datasource, the service automatically maps the datasource to the connection Write-Host "Binding semantic model to connections" $authToken = Get-FabricAuthToken # 'gatewayObjectId' as '00000000-0000-0000-0000-000000000000 indicate the connection is a sharable cloud. $body = @{ "gatewayObjectId"= "00000000-0000-0000-0000-000000000000"; "datasourceObjectIds" = $connectionsToBind } | ConvertTo-Json $headers = @{'Content-Type'="application/json"; 'Authorization' = "Bearer $authToken"} Invoke-RestMethod -Headers $headers -Uri "https://api.powerbi.com/v1.0/myorg/groups/$workspaceId/datasets/$($semanticModelImport.Id)/Default.BindToGateway" -Method Post -Body $body
- dmkblesser
Advocate II
Hi aakhpggm, this worked like a charm. Thank you so much.
Funny enough, I have been talking to both Microsoft and Databricks on this one. Databricks introduced the Power BI Taskflow and requires user to manually bind the gateway as they stated there is no api available to bind the cloud connection. Microsoft also mentioned this is a known gap and asked me to vote up the idea.
- ibarrau
Super User
Hi. The bind is only for Gateway. After you configure a gateway and a source you can set a source to the dataset. But, if you are connecting to cloud sources that's not an option. The most similar thing I have seen at the Fabric Rest API (it's kind of new), it's updating connection. It let's you change the connection and credentials of a dataset. I'm not sure how the body is built, it's really new and I haven't tried it yet. You can read about it here: https://learn.microsoft.com/en-us/rest/api/fabric/core/connections/update-connection?tabs=HTTP
I don't think there is another way.
I hope that helps,