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);

console.log(jsonObject);

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.

1 Like

@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

@chartley22:

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!

1 Like

@chartley22: Great :clap:

I am glad it worked. Good day!

1 Like

Hi,
I am doing SOA webservice testing . While pass XML able to see response data successfully.

But I want to store response data in environment .

Issue:

Paymentid(refer screenshot) response data want to save in environment setup.

Environment - payment I’d shows “null”(refer screenshot). Help me

@AzhaguBanca Welcome to the community :partying_face:

SOAP response should be handled differently compared to JSON parsing.

So here in your case,

pm.environment.set("paymentid", jsonData['soap:Envelope']['soap:Body']['tns:DetailPayment']['tns:PaymentId']);

I have tried roughly based on the visible response. If not working, please provide me the full response :slight_smile:

Also kindly read the below link if you need to know more about SOAP response parsing.

Please create a separate topic in future for your queries, so that it will be addressed. Also I request you to consider the points here for your next query here.

3 Likes

Thank you so much @bpricilla . it is working as expected.

2 Likes

@AzhaguBanca That’s wonderful, try exploring cheerio, it will be easy when you are parsing a bigger response :slight_smile:

1 Like

@bpricilla Can you please help on the below concerns. waiting for positive feedback.

https://community.postman.com/t/want-to-get-data-like-count-and-individual-payment-details-from-list-of-payments-for-my-xml-response-i-e-each-payment-payment-no-date-related-details-from-list/22376

1 Like

@AzhaguBanca Sure, it needs a bit attention. It might go on for a ping pong game here :blush: Please drop me a email or a message in LinkedIn. We will connect :partying_face: