Use a JSON parameter on body XML field


I am trying to test a SOAP webserver with Postman and I was able to, but now I need to automate it.

Pre-Request Script
On pre-request script, I create a JSON structure to be possible to create more than one test at the same time and then I create a copy of that structure and update the values what I need and put that in a environments variables

On Test, I pick the global variables and check if the “Tests” array in at the end, if is, the test will finish, if not will call the same request

On Body, I have a SOAP structure and I am not getting the value of “” or “body.description”

Someone can tell me what I need to do to fix the body issue, please?

Hi @ricardorio28,

Very nice setup! From what I see, I don’t think you can do what you are trying to achieve.

First, it looks like your proper syntax would be {{}} or {{body.description}}. However, in the case when using for your XML body for your POST request, you can’t reference variable values in that same way. In a Pre-Request Script or Tests section, you can, but not here.

The variable reference pulls out strings, and not JSON objects, when being used in the raw request body.

I would suggest creating a “bodyName” variable, and a “bodyDescription” variable, which should then resolve this issue.

I hope this helps!

1 Like

Thanks :wink:

I will need to do that but I will try something more dynamic…I am thinking to create a function on global variables to create the environment variables for me…something like this…with this will be easier to send the values for the “postman body”

(jsonObject) => {
for ( var parameter in jsonObject ){
pm.environment.set(parameter, jsonObject[parameter]);

Hi @ricardorio28,

I think thats a good idea and should suffice. You can even do value teardown if you’d like in the tests section. This I believe would solve your issue where you need dynamic values.

You would just need to parse the jsonObject in the pre-request script using var jsonObject = JSON.parse(globalEnvJsonString) and then you can reference it as a json object natively.

Additionally, from your current example, you shouldnt have to loop through your jsonObject, unless there was an array, to assign the variable you can just use the following:

pm.environment .set(bodyName,

But if you had an array of these objects, then I would look through them.

Of course the syntax depends on how you structure the json, but all in all, should be very doable.