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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...