AnsweredAssumed Answered

Help with API calls to Asset Management/Asset Viewer

Question asked by Aaron Bailey on Dec 6, 2019
Latest reply on Dec 9, 2019 by putter101

I am trying to use PowerShell to interact with the asset management application but I am encountering issues with authentication.

 

This is the curl command that I'm trying to emulate using PowerShell.

curl -u [username/password removed] -H "content-type: text/xml" -X "POST" 
--data-binary @- "https://qualysapi.qualys.eu/qps/rest/2.0/search/am/hostasset" < [location of xml file]

I've written the below PowerShell to access the Asset Management API

$username = 'username'
$password = 'password'
$body = 'location of xml file'
$header = @{"Authorization" = "Basic" + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('$username':'$password'))}

invoke-restmethod -Method POST -header $header -ContentType "text/xml" -body $body -uri "https://qualysapi.qualys.eu/qps/rest/2.0/delete/am/asset/hostasset"

The call returns an error regarding authentication.

 

Can anyone offer advice or feedback?

Outcomes