Forum Discussion

powerbi_jenhen's avatar
powerbi_jenhen
Resolver II
2 years ago
Solved

Power BI Rest API via Powershell

Hi,   I have the below $Body variable to use within my API Invoke command, how can I exit the single quotes to reference my $server and $database variables? I currently receive the error: "DMTS_Uns...
  • powerbi_jenhen's avatar
    2 years ago

    The issue was my server variable required "\\" not "\". Code that worked for me:

    $Body = ConvertTo-Json -Depth 4 -InputObject $(@{
            dataSourceType = "Sql"
            connectionDetails = '{"server":"'+$server.Replace("\","\\")+'","database":"'+$database+'"}'
            datasourceName = $sourceName
            credentialDetails = @{
                credentialType = $credentialDetails.credentialType
                credentials = $credentialDetails.credentials
                encryptedConnection = $credentialDetails.encryptedConnection
                encryptionAlgorithm = $credentialDetails.encryptionAlgorithm
                privacyLevel = $credentialDetails.privacyLevel
            }
        })