AnsweredAssumed Answered

Asset Tagging (ID not found ? )

Question asked by Matt Riat on Sep 29, 2017
Latest reply on Oct 2, 2017 by Matt Riat

Hi Community,

Looking for some help here. Below you'll find some basic Powershell that I have thrown together to Tag an asset. The creation of the tag is successful. I can view and have an ID for that tag in Qualys. I can also view and have an ID for the device I am looking to tag in Qualys. In review of several help examples provided here on the community (Using Curl examples) I am pretty sure my Uri is correct. Yet when I post my content my response is that the ID is not found. ?

 

# Prompt User to enter their Qualys API UserName and Password

$username = Read-Host -Prompt 'Enter your Qualys UserName:'

$password = Read-Host -Prompt 'Enter your Qualys Password:'

# HardCoded values for both the TAG Identifier and Qualys Device ID. Change these values to a tag/device ID you may own

$TheTagID = "1181507"

$QualysAssetID = "3535110"

# Convert Pwd to Secure Str

$password_base64 = ConvertTo-SecureString $password -AsPlainText -Force

$creds = New-Object System.Management.Automation.PSCredential ($username, $password_base64)

$authInfo = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$username`:$password"))

$headers = @{"X-Requested-With"="powershell";"Authorization"="Basic $authInfo"}

#  What I have found is that I cannot send the actual XML document but a String instead. This has worked when creating a tag

$DBody = "<ServiceRequest><data><HostAsset><tags><add><TagSimple><id>$TheTagID</id></TagSimple></add></tags></HostAsset></data></ServiceRequest>"

#  The Uri to update a Device with a tag based on examples provided in the community...note this may change depending on your subscription/location

$url = "https://qualysapi.qualys.com/qps/rest/2.0/update/am/hostasset/$QualysAssetID"

#  Invoke Rest, Pass header,creds and Body and Content type as Post...export xml to a file for testing

Invoke-RestMethod -Headers $headers -Uri $url -Method Post -Credential $creds -Body $DBody -ContentType "text/xml" -OutFile "D:\TagResponse.xml"

 

Has anyone ran into this issue before? I assume so. What was your fix? There is not many Powershell examples here in the community so perhaps this bit of code will help someone out.

 

Qualys API Response:

response

Any help you can provide is appreciated..

Thanks!!

-MR-

Outcomes