Forum Discussion
FABRIC REST API Connections - Create Connection
Does anyone know how to run this API via a PowerShell script to create a SQL Server cloud connection for a semantic model using Service Principal authentication?
Here's what I have so far:
Invoke-PowerBIRestMethod -Url "https://api.fabric.microsoft.com/v1/connections" -Method Post -Body $body
But I don't understand how to construct the body
Thanks in Advance,
Charline
Hi
$body = @{
connectivityType = "ShareableCloud"
displayName = "SQL Server Connection"
connectionDetails = @{
type = "SQL"
creationMethod = "SQL"
parameters = @(
@{ dataType = "Text"; name = "server"; value = "XXX" },
@{ dataType = "Text"; name = "database"; value = "XXX" }
)
}
privacyLevel = "Organizational"
credentialDetails = @{
singleSignOnType = "None"
connectionEncryption = "Encrypted"
skipTestConnection = $false
credentials = @{
credentialType = "ServicePrincipal"
tenantId = "XXX"
servicePrincipalClientId = "XXX"
servicePrincipalSecret = "XXX"
}
}
} | ConvertTo-Json -Depth 10
5 Replies
- Prince0011
Memorable Member
Hi,
Here's a working body structure for SQL Server + Service Principal:
$body = @{
connectivityType = "ShareableCloud"
displayName = "SQL Server Connection"
connectionDetails = @{
type = "SQL"
creationMethod = "SQL"
parameters = @(
@{ dataType = "Text"; name = "server"; value = "yourserver.database.windows.net" },
@{ dataType = "Text"; name = "database"; value = "yourdatabase" }
)
}
privacyLevel = "Organizational"
credentialDetails = @{
credentialType = "ServicePrincipal"
credentials = @{
tenantId = "your-tenant-id"
servicePrincipalClientId = "your-client-id"
servicePrincipalSecret = "your-client-secret"
}
singleSignOnType = "None"
connectionEncryption = "Encrypted"
skipTestConnection = $false
}
} | ConvertTo-Json -Depth 10
Call it against api.fabric.microsoft.com directly, double check field casing against current docs since it's picky.
If this helped, feel free to give it a kudos or mark it as solution, helps others find it too.
- v-sathmakuri
Community Support
Hi Charline_74 ,
Could you review the suggestion provided above and let us know if you have any additional questions, we are happy to address.
Thanks!!
- Kagiyama_yutaka
Skilled Sharer
I think there are two separate calls here. POST /v1/connections creates the SQL cloud connection; binding it to the semantic model uses bindConnection. For SP auth, put credentialType, tenantId, servicePrincipalClientId, and servicePrincipalSecret under credentialDetails.credentials. One catch: the bindConnection caller needs to own the semantic model.
- Charline_74
Resolver I
Hi
$body = @{
connectivityType = "ShareableCloud"
displayName = "SQL Server Connection"
connectionDetails = @{
type = "SQL"
creationMethod = "SQL"
parameters = @(
@{ dataType = "Text"; name = "server"; value = "XXX" },
@{ dataType = "Text"; name = "database"; value = "XXX" }
)
}
privacyLevel = "Organizational"
credentialDetails = @{
singleSignOnType = "None"
connectionEncryption = "Encrypted"
skipTestConnection = $false
credentials = @{
credentialType = "ServicePrincipal"
tenantId = "XXX"
servicePrincipalClientId = "XXX"
servicePrincipalSecret = "XXX"
}
}
} | ConvertTo-Json -Depth 10 - codeautomation
Advocate I
The body structure looks right for a ShareableCloud SQL connection with Service Principal authentication.
A couple of things I’d verify:
- the service principal has access to the SQL source
- the app/service principal has the required Fabric permissions
- tenantId, servicePrincipalClientId, and secret are all valid
- ConvertTo-Json -Depth 10 is kept, otherwise nested credential objects may be truncated
For debugging, I’d also inspect the final JSON before the API call:
$body
If the request still fails, the HTTP response body from Invoke-PowerBIRestMethod should help identify whether the issue is authentication, permissions, or the connection payload itself.