I'm trying to get a specific field value from a http post response via a powershell script so i can use it as a variable in the script itself. Is there a way to do this without writing the response to a new file
The code looks like this:
$HEADERS
$RequestBody = @"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AutotaskIntegrations xmlns="http://autotask.net/ATWS/v1_5/">
</AutotaskIntegrations>
</soap:Header>
<soap:Body>
Create Ticket Function for API I'm using
</soap:Body>
</soap:Envelope>
"@
Invoke-WebRequest -Uri $AUTOTASK -Method Post -Body $RequestBody -ContentType $ContentType -UseBasicParsing -Headers $Headers;
$UpdateBody = @"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AutotaskIntegrations xmlns="http://autotask.net/ATWS/v1_5/">
</AutotaskIntegrations>
</soap:Header>
<soap:Body>
<update xmlns="http://autotask.net/ATWS/v1_5/">
<Entities>
<Entity xsi:type="Ticket" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>field i need to populate</id>
</Entities>
</update>
</soap:Body>
</soap:Envelope>
"@
Invoke-WebRequest -Uri $AUTOTASK -Method Post -Body $UpdateBody -ContentType $ContentType -UseBasicParsing -Headers $Headers;
What I'm doing is creating a ticket, and my goal is to update that ticket with a value that is returned from the creation of the ticket.
The response from PowerShell is a giant block of XML and the field I need from it looks something like <id>12345</id>
.
Is there a way to parse that one field and use it in the same script without exporting the response to a new file?