ger0001p
(Philipp Gerstenberger)
October 11, 2019, 7:34am
1
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!
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.
ger0001p
(Philipp Gerstenberger)
October 11, 2019, 12:24pm
3
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.
1 Like
ger0001p
(Philipp Gerstenberger)
October 15, 2019, 6:54am
5
danny-dainton:
let res = xml2Json(pm.response.text()); pm.environment.set(“TOKEN”, _.get(res, ‘response.result.key’))
Perfect. Works just fine. Thank you Dannydainton
1 Like