Put Output key to environment variable

Hi Postman Community,

I´ve got one question. My request gets following response in XML format.




How can I set the key to the environment variable “TOKEN”?

Thanks and best regards

Hey @ger0001p,

Welcome and thank you for the question! :trophy:

Are you able to post an image of the response body?

The syntax to set the variable value would be something like pm.environment.set("TOKEN", pm.response.text()) but without seeing the full response and the way that it’s presented, it’s difficult to know for sure.

Hi @dannydainton

thanks for your reply. Yes of course. Attached a screenshot of the response body.


You could try something like this:

let res = xml2Json(pm.response.text());

pm.environment.set("TOKEN", _.get(res, 'response.result.key'))

I’m sure there are many different ways to get that value though. :slight_smile:

1 Like

Perfect. Works just fine. Thank you Dannydainton :slight_smile:

1 Like