AnsweredAssumed Answered

API Script no longer works after API update

Question asked by Erich Lengfeld on Feb 9, 2017
Latest reply on Feb 9, 2017 by Jeff Leggett

After recent API update my script no longer works see below:

SCRIPT

 

$user = "q_user"
$pass = "q_Pass"
$authInfo = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$user`:$pass"))
$headers = @{"X-Requested-With"="powershell";"Authorization"="Basic $authInfo"}
#API call to get Report ID
Invoke-RestMethod -Uri "https://qualysapi.qg2.apps.qualys.com/api/2.0/fo/report/?action=list" -headers $headers -Method post -OutFile C:\xxxxx
[xml]$XML = Get-Content C:\xxxx
#$XML.REPORT_LIST_OUTPUT.RESPONSE.REPORT_LIST.REPORT.ID
#Pull report of servers in Qualys 
$NewestReport = $XML.REPORT_LIST_OUTPUT.RESPONSE.REPORT_LIST.REPORT.ID[0]
Invoke-RestMethod -Uri "https://qualysapi.qg2.apps.qualys.com/api/2.0/fo/report/?action=fetch&id=$NewestReport&echo_request=1" -headers $headers -Method get -OutFile C:\xxx

 

ERROR:

Invoke-RestMethod :
Access Denied (authentication_failed)
Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.
This is typically caused by an incorrect username and/or password, but could also be caused by network problems.
For assistance, contact your network support team.
At C:\xxxxxx
+ Invoke-RestMethod -Uri "https://qualysapi.qg2.apps.qualys.com/api/2.0/fo/report/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

 

When I use the account to log into the site directly it works so it is not invalid creds. 

Outcomes