Parsing XML variables to enivornment

Adam
Tue, 09 Aug 2022 02:27:20 +0000
Help Hub

Hi Everyone!
Quite new to postman, but have managed to created a few basic API’s and looking at my first real integration project.
I have an API spitting out a response and I am trying to extract the ‘WorkOrderNumber’ in the following response:

``<?xml version="1.0" encoding="utf-8"?>
``<feed xml:base="http://mex.viterra.com.au/MEXData/OData.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <id>http://mex.viterra.com.au/MEXData/OData.svc/WorkOrders</id>
WorkOrders
    <updated>2022-08-09T02:19:57Z</updated>

    <entry>
        <id>http://mex.viterra.com.au/MEXData/OData.svc/WorkOrders(134031)</id>
        <category term="MEXModel.WorkOrder" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />


        <updated>2022-08-09T02:19:57Z</updated>
        <author>
            <name />
        </author>
        <content type="application/xml">
            <m:properties>
                <d:WorkOrderID m:type="Edm.Int32">134031</d:WorkOrderID>
                <d:WorkOrderNumber m:type="Edm.Int32">131401</d:WorkOrderNumber>
            </m:properties>
        </content>
    </entry>
</feed>
``

In my Test Script I have tried the following:
``
var responseJson = xml2Json(responseBody);
var WorkOrderNumber = responseJson['feed']['entry']['content']['m:properties']['d:WorkOrderNumber'];
pm.environment.set("LastWONumber", WorkOrderNumber);

The response has what I need, the number but with additional text:
{_: “131401”, $: {…}}

1. _: “131401”

2. $: {…}

3. m:type: “Edm.Int32”

I just want the number 131401 so I can pass to a variable to LastWONumber but it appears to pass all that information, not just the number.

Any hep please?

5 posts - 2 participants