Need help saving GET request response in XML format (or converting to JSON) and then doing a POST request after

Hi all,

The response body from a GET request I’ve set up returns variables of this format:

I simply would like to call on this data exactly how it is (or convert it into JSON if that is easier, but would prefer to keep as XML) and POST this data in another request.

Thank you for any assistance!

Please note, I know you can simply copy and paste the response text, but I would like to set up a script that will run and do this automatically

@chartley22: Welcome to the Community :wave:

So to understand your question better, you need to pass the entire response to another request? And I believe your response is in XML format.

You need to store your response in a variable like below:

pm.environment.set(“SOAP_Request”, (responseBody));

And you can directly pass this to your next request body {{SOAP_Request}}

Else you have the option to convert into JSON by using below snippet:

var jsonObject = xml2Json(responseBody);


If its not relevant, please share more details with screenshots :slight_smile:

@bpricilla, thank you very much for your response!

I had already tried your first suggestion, but not your second. Unfortunately, both still fail. I’m working with a channeladvisor feed and trying to send the response to sellercenter. Strangely, if I run a POST request with the body as a ‘copy-paste’ exact of the text above, it is successful.

However, when running and calling on variables, it does not return a success, and comes with an “invalid request error” message. I understand that this may be not at fault of the writing of the script, but I do believe if it works via copy-paste that some solution exists via scripts.

Perhaps it is sending purely {{SOAP_Request}} instead of the text inside? I’m unsure. Both requests are in the same collection and are using the same environment. Hopefully this insight is helpful!

@chartley22, thanks for the details. So how do you pass your body? in which format?

If its raw, are you selecting the XML format ?

@bpricilla I believe the issue is currently with storing the reponse in a variable. As per the attached images, an error is returned with the test script (it wasn’t before though, so unsure what is happening now) when written as suggested. As for the POST script, I’ve simply been calling on the variable in XML as shown.

@chartley22: I believe you have stored the variable in the “Tests” section of your first GET request. Then please check in the environment variable section if the new variable is generated and the XML response is stored properly.

@bpricilla no it is not being generated in the environment. I’ve tried running pm.environment.set(“SOAP_Request”, (responseBody)); both in the body of the GET request and in the test section, but neither create a variable named SOAP_Request to be called upon in the POST request


Can you please edit the quotes for the variable. It should look like:

It should be in only Test section and not in the body of the GET request.

@bpricilla wow, thank you. Didn’t even realise that the quotations were in some kind of different font. I believe this works now. I cannot thank you enough!

@chartley22: Great :clap:

I am glad it worked. Good day!