Jump to content

API and Powershell


Recommended Posts

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") 
$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

Link to comment
Share on other sites

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 = @{}





Let me know if you succeed.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...