Why is my converted postman powershell code returning empty brackets?

461 views Asked by At

I am able to successfully leverage postman for an API call I am making to qualys but now I am attempting to convert it into powershell, or powershell ISE, and I get all these empty brackets and am not sure how to troubleshoot or understand these results. Does this mean I have successfully authenticated and the results just are not readable yet?

To be clear I am converting Postman testing into the 'Powershell Rest Method' Snippet. This is the result of that snippet which was successful in postman.

add-type -AssemblyName System.Net.Http
$browser = New-Object System.Net.WebClient
$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-Requested-With", "blahblah")
$headers.Add("Authorization", "Basic blahblahblahblahblahblahbl==")

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "action"
$StringContent = [System.Net.Http.StringContent]::new("list")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "echo_request"
$StringContent = [System.Net.Http.StringContent]::new("1")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "ag_ids"
$StringContent = [System.Net.Http.StringContent]::new("12345,12345,12345,12345")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "no_vm_scan_since"

$StringContent = [System.Net.Http.StringContent]::new("2020-04-13")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$body = $multipartContent

$response = Invoke-RestMethod 'https://qualysapi.qualys.com/api/2.0/fo/asset/host/' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
[
    [

    ],
    [

    ],
    [

    ],
    [
        [

        ],
        [
            "System.Xml.XmlWhitespace",
            "System.Xml.XmlElement",
            "System.Xml.XmlWhitespace",
            "System.Xml.XmlElement",
            "System.Xml.XmlWhitespace",
            "System.Xml.XmlElement",
            "System.Xml.XmlWhitespace"
        ],
        [

        ]
    ],
    [

    ]
]
0

There are 0 answers