I'm a newbie when it comes to using soap and rest, so don't assume I know what I'm doing. I've been doing some google searching and have confused myself more that I've helped.
I'm unable to extract the "Status" of connecting to a site using "Invoke-RestMethod" in PowerShell. When I use the "outerxml" option, I'm able to pull back all of the data that's returned (look at the attached file), but I'm unable to extract only the "Status", which is what I need.
I'm using code that I extracted from Postman to connect to the site, which works, but I'm unable to extract data I need using different methods.
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/soap+xml; charset=utf-8")
$body = @"
<s:Envelope xmlns:s=`"http://www.w3.org/2003/05/soap-envelope`" xmlns:a=`"http://www.w3.org/2005/08/addressing`">
<s:Header>
<a:Action s:mustUnderstand=`"1`">YOUR_URL_HERE</a:Action>
<a:MessageID>urn:uuid:MessageID</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand=`"1`">YOUR_URL_HERE</a:To>
</s:Header>
<s:Body>
<LogOn xmlns=`"http://www.ultipro.com/dataservices/bidata/2`">
<logOnRequest xmlns:i=`"http://www.w3.org/2001/XMLSchema-instance`">
<UserName>USER</UserName>
<Password>PASS</Password>
<ClientAccessKey>CACCESSKEY</ClientAccessKey>
<UserAccessKey>UACCESSKEY</UserAccessKey>
</logOnRequest>
</LogOn>
</s:Body>
</s:Envelope>
"@
$response = Invoke-RestMethod 'YOUR_URL_HERE' -Method 'POST' -Headers $headers -Body $body
## This one prints the text that's in the attached screenshot
$response.outerxml
## This code gives me nothing
#$Data = ([xml]$R.RawContent).Envelope.Body.LogOnResponse.LogOnResult.ClientAccessKey.Innertext
#write-host "$Data"
## This code also gives me nothing
#$XPath = '//*[local-name()="Status"]'
#$Nodes = (select-xml -xml $response -XPath $XPath).Nodes
#$Nodes
I have tried the code that I have commented out (I got it from google searching). When I try the code I do not get an error nor do I get results.
What am I doing wrong to extract the data I need? Thanks.
[EDIT] I had to remove my altered URL's to get it to post because it marked my question as spam.. :( I also don't see my screenshot I attached so below is the output from the embedded code that I'm trying to pull the status from:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">YOUR_URL_HERE</a:Action>
<a:RelatesTo>urn:uuid:xxxxxxxx</a:RelatesTo>
</s:Header>
<s:Body>
<LogOnResponse xmlns="YOUR_URL_HERE">
<LogOnResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ServiceId>xxxxxxx</ServiceId>
<ClientAccessKey>xxxxxxxx</ClientAccessKey>
<Token>xxxxxxxxxxxxxxx</Token>
<Status>Ok</Status>
<StatusMessage i:nil="true" />
<InstanceKey>xxxxxxxxxx</InstanceKey>
</LogOnResult>
</LogOnResponse>
</s:Body>
</s:Envelope>