Matt 1 Posted December 21, 2018 Report Share Posted December 21, 2018 I'm trying to build an interface between Domotz and our documentation program marrying the information in SQL Server. Any ideas for getting the connection to the API working properly? This is definitely not connecting since I'm seeing no incremental access to the API key in the portal. TIA! $conn = New-Object System.Data.SqlClient.SqlConnection("Server=SERVER;Database=Information;Integrated Security=True") $conn.Open() $cmd = $conn.CreateCommand() $Uri = 'https://api-us-east-1-cell-1.domotz.com/public-api/v1/agent' $headers = @{ 'Accept' = 'application/json' 'X-Api-Key' = 'XXXXXX' } $result = Invoke-WebRequest -Uri $Uri -Headers $headers -Method Get Yields the following: Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At line:1 char:11 + $result = Invoke-WebRequest -Uri $Uri -Headers $headers -Method Get + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand Quote Link to post Share on other sites
Giancarlo 53 Posted December 21, 2018 Report Share Posted December 21, 2018 I'm not an expert on Powershell, but reading the code it seems there might be an issue in the headers definition, since there is no delimiter between the two definitions: $headers = @{ 'Accept' = 'application/json' <<--- Missing something? 'X-Api-Key' = 'XXXXXX' } Please, try with the following approach to add the headers: $headers = @{} $headers.add("Accept","application/json") $headers.add("X-Api-Key","XXXXXX") source: https://stackoverflow.com/questions/12936150/is-it-possible-to-send-additional-http-headers-to-web-services-via-new-webservic Let me know if you succeed. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.