I am trying to use the Invoke-RestMethod command to grab the XML response from a SOAP endpoint and convert it to JSON text. From what I have read, the Invoke-RestMethod should be converting the response to a custom object for me so this should be really simple... This is what I am trying....
$APIRequest = Invoke-RestMethod -Method Post -Uri $SOAPEndpointURL -Headers $requestHeader -Body $requestBody
$JSONResponse = ConvertTo-Json $APIRequest.Envelope -Depth 9
But this is what i get as the resulting JSON text?
[ [ [ [ [ [ [ [] ], [], [ [] ], [], [ [] ], [ [] ], [ [] ], [ [] ], [ [] ], [ [] ], [ [] ], [ [] ], [ [] ], [], [], [ [] ], [ [] ], [ [] ], [ [] ], [], [ [] ], [ [] ], [ [] ], [ [] ], [], [ [] ], [ [] ], [ [] ], [ [] ] ] ], [ [] ], [] ] ] ] ]
Can anyone suggest a standard way to do this without trying to interpret the XML response manually as XML text?
If I update my request to create an output file too then I can see the proper XML response in the file.
$APIRequest = Invoke-RestMethod -Method Post -Uri $SOAPEndpointURL -Headers $requestHeader -Body $requestBody #-OutFile "C:\SOAPResponse.txt"
If I change my conversion to not have the "-Depth 9" then the result is now this which is confusing?
[ [ [ "System.Xml.XmlElement" ] ] ]
To provide more detail, this is what the XML looks like when I call the end point using PostMan.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetCustomerListResponse>
<GetCustomerListResult>
<Data>
<Customer>
<AddressLine1>123 Yellow Street</AddressLine1>
<AddressLine2/>
<AddressPostCode>1234</AddressPostCode>
<AddressState/>
<AddressSuburb>Sydney</AddressSuburb>
<Email>[email protected]</Email>
<PgnRowNo>1</PgnRowNo>
</Customer>
</Data>
<Error>0</Error>
<ErrorMessage i:nil="true"/>
</GetCustomerListResult>
</GetCustomerListResponse>
</s:Body>
</s:Envelope>
[xml]$APIRequest = .....before converting to Json?