Forum Discussion
daive
1 year agoRegular Visitor
Script a new connection
Hi all, Is it possible to script a new connection? As in this action: This is my script, its failing with a 404 Not Found $tenantId = "<tenant-id>"
$clientId = "<client-id>"
$clie...
- 1 year ago
Hi daive , I think
- connectionDetails must be a JSON string (not nested).
- credentials must be Base64-encoded.
- Credentials must be encrypted using the gateway's public key.
- And Ensure you have relevant API Permissions
If this post helped please do give a kudos and accept this as a solution
Thanks In Advance
MaZoSR
1 year agoFrequent Visitor
The Power BI API does not support ServicePrincipal as the credentialType. You will have to use the Fabric API instead.
You will also have to encrypt the Service Principal credentials. This can be done as follows (using the pre-release v5 version of the Microsoft.PowerBI.API library - unfortunately no helper class exists for ServicePrincipal so doing this manually instead):
$credentialData = @{
credentialData = @(
@{
name = "tenantId"
value = $tenantId
},
@{
name = "servicePrincipalClientId"
value = $clientId
},
@{
name = "servicePrincipalSecret"
value = $secret
}
)
} | ConvertTo-Json -Depth 3
$gatewayKeyObject = [Microsoft.PowerBI.Api.Models.MicrosoftPowerBIApiModelFactory]::GatewayPublicKey($gatewayExponent, $gatewayModulus)
$credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObject)
$spnCreds = $CredentialsEncryptor.EncodeCredentials($credentialData)
$credentialDetails = @{
singleSignOnType = "None"
connectionEncryption = "Any"
skipTestConnection = $true
credentials = @{
credentialType = "ServicePrincipal"
values = @(
@{
gatewayId = $gatewayId
encryptedCredentials = $spnCreds
}
)
}
}