Parameterize a 'chunk' of xml for a SOAP request

Hello,

I am trying to test a range of different instances with a SOAP query that is for the most identical across instances but also has a part of the request body that is unique from one instance to another. So far I have managed to create global variables for URL etc. without any problems.

But what I need now is to capture a big piece of xml; tags, attribute and content all in one go into one parameter. I am thinking I could maybe use a data file and store the variable there and then insert it into the whole XML request. I guess a great deal of paring and escaping characters is needed if this is at all possible.

I look forward to hear your ideas!

EDIT: Please excuse me for bumping my own post just this once. For clarity, I am looking for a solution similar to the one demonstrated by @vdespa below, but for a SOAP request and an XML file.

Hi @magnus_r,

While I am not exactly sure how you would like to accomplish your goal, I’d like to refer you to a video I made regarding using XML with Postman Tests and Pre-Request Script sections, using cheerio.js, as this might help.

To better assist though, can you provide an example chunk of XML you’d like to parameterize? Ideally, this should work the same way as in @vdespa video, then in your request body, you write out the raw XML and insert the XML variables in your raw xml, like so

<parentTag>
    <childtag>
        {{param1}}
        {{param2}}
    <childtag>
    {{param3}}
</parentTag>  

Let me know if something like the above makes sense.

Best,
Orest

1 Like

Hi @magnus_r,

could you share e simple example? It can be more clearer what you are trying to do.

You don’t need to replace the entire body as shown in the video but just parts of it as @odanylewycz explained.

1 Like

Hello @odanylewycz and @vdespa.

Thank you both for your responses, I have watched each of your videos and parts of the answer I am looking for is probably in both of them.

I realize ‘chunk’ is not a very exact term. Payload is a better term and in my case a payload is a document with several lines of unique xml. A simplified anonymized example below. The point is that the payloads differ wildly, some may have some 30 unique tags.

payloadOne.xml

<uniqueXml>
    <Plan id="00001111abc">
         <IdNumber>12345678</IdNumber>
    </Plan>
</uniqueXml>

payloadTwo.xml

<uniqueXml>
    <Plan id="9998881xyz">
        <Firstname>Bob</Firstname>
        <LastName>Dobbs</LastName>
        <Adress>
            <StreetName>Street</StreetName>
            <PostalCode>45678</PostalCode>
            <City>City</City>
        </Adress>
    </Plan>
</uniqueXml>

And in Postman I have a request body like so: I wish to insert the one payload into {{payload}}

<soapenv:Envelope>
   <soapenv:Body>
      <genericBegin>
         <moreGeneric>
            {{payload}}
         </moreGeneric>
      </genericBegin>
   </soapenv:Body>
</soapenv:Envelope>

I am aware that I can use iteration data to point to an external file, and I have used cheerio for testing xml responses, but I need to combine different approaches in this scenario. I hope my question is clearer now.

Hi @magnus_r,

Thanks for clarifying, I think I understand better, but let me know if my understanding is correct based on my response below.

What you can do is save the XML payloads as environment variables. Then when you need to use the payload in your script, you can pull them out from the environment. Lastly, if you need change anything about the XML payload before inserting it into your wrapper XML, you can initialize the XML as a cheerio object, manipulate the values, then deserialize the cheerio object back to XML and use it in your payload.

Let me this sound like what you’re looking for, and if so, let me know code examples / scenarios you’re looking for.

1 Like

Hi @odanylewycz , what you describe is a first step to to what I am looking for indeed, and I have now managed to put in place what you describe. Instead of environment variables I use global variables, but otherwise the same idea.

Right now I have a hardcode global payload variable defined for the xml . Since ultimately I will use Newman in the solution I use that as an example here.

" --global-var "payload= <uniqueXml>
    <Plan id='00001111abc'>
         <IdNumber>12345678</IdNumber>
    </Plan>
</uniqueXml>"

But the catch is, I already have a repo with xml payload documents (Earlier we used Fitnesse framework at my company and we have a repo of existing xml payloads that I would like to reuse in Postman) I would also like to have the newman commands shorter.

What I would like to have in the end would look have a path to the doc - something short and sweet like this:

" --global-var "payload= folder/payloadOne.xml"

That is what I mean by parameterize a chunk of xml.

All the examples I see for Postman indicate I can use either json, and csv files to set key value pairs for iterationdata. I will probably have to create a json document where I create a payload key and set the value to the xml (I just experimented with this and I get unexpected end of string line errors unless I remove all line breaks).

[
    {
        "payload": "<uniqueXml><Plan id=\"00001111abc\"><IdNumber>12345678</IdNumber></Plan></uniqueXml>"       
    }
]

Storing xml in json seems very counterintuitive to me, and I would much rather just point to the path to the xml document if possible.

1 Like

Hi @magnus_r,

Interesting use case. I have not had much experience with this, but I certainly see what you are trying to do.

Given that you want to use newman at the end of it, what may work is using the file system module, and read the xml file from there, which makes is a native nodejs file. From there, you can define a string output of the file to another variable, say a payload variable, and then use that as your payload for your request.

const fs = require('fs');
fs.readFile('/folder/payloadOne.xml', 'utf8' , (err, data) => {
  if (err) {
    console.error(err)
    return
  }
  var payload = data
})

I am not sure how well this would work, but it should in theory. While its not the elegant solution you were looking for, it should help and ideally make your newman command shorter as this code would be in a node.js script.

Let me know if this helps!