Desktop Central PowerShell Authentication

Desktop Central PowerShell Authentication

While I have been programming in PowerShell for years, getting to data using an API is a bit new to me.  I have only successfully done this so far by connecting to Meraki's API.  So far, I am having no luck connecting to Desktop Central.

Below is a script I am trying to use to get authenticated.  It is possible that I am missing pieces, or just have something typed out incorrectly.

API scripting via PowerShell is always a bit light on documentation with many products, and most sites assume you are programming in Python or something else, so it takes a bit of thought to get everything converted to what works in PowerShell.

Some of this is put together by bits and pieces found within the forums here.

Once I get the authentication piece down, I should have no difficulty in grabbing the data that I want to get to.

$username = "admin"
$password = "superstrongpassword"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($password)
$password64 = [Convert]::ToBase64String($bytes)

$apikey = '12345678-90AB-CDEF-1234-567890ABCDEF'

$header = @{TECHNICIAN_KEY=$apikey;}
$body   = @{username = $username; password = "$password64"; auth_type = 'local_authentication'; format = 'json'}

$url = 'https://server.domain.org:8383/api/1.0/desktop/authentication'
$request = Invoke-RestMethod -Method POST -Uri $url -Headers $header -Body $body 
return $request


I always end up with this as a result:
error_description : Username and password did not match
message_type      : authentication
error_code        : 10001
message_version   : 1.0
status            : error

I have tried
  1. Adding -ContentType "application/json" to the Invoke-RestMethod cmdlet.
  2. Unicode.GetBytes instead of ASCII
  3. No quotes on "$Password" in $body
  4. 1.2 and 1.3 for the version in the URL.  (1.3 is higher than what is in use is an error I received)
  5. Not having format = 'json'
Authentication does work when I go to Admin > API Explorer, then choose Authentication > Login from the left, Local Authentication, then enter my credentials.



                New to ADManager Plus?

                  New to ADSelfService Plus?