Put Output key to environment variable

Hi Postman Community,

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

"


LUFRPT1yaDN6T09CZ0dXNlRzSkFZcFRORVI5VkwzOWs9VEp1bS9YWDR2Q05BYmVvcGRuUlJwa2xTd0x0QVFtOGRNRUNiTm1rSm15TWV2S3FPeFVJREZkU2t2cUgrS29xdw==


"

How can I set the key to the environment variable ā€œTOKENā€?

Thanks and best regards
Philipp

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 @danny-dainton

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

Greetings
Philipp

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