Answer the question
In order to leave comments, you need to log in
How to save token from response xml to variable, in postman?
I use postman to access the api, first I make a POST request for authorization, in the response there is a token that I want to save to an environment variable (so that I can use it for authorization in other requests).
An answer like this:
<?xml version='1.0' encoding='UTF-8'?>
<Response xmlns="http://site.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://site.com/api http://site.com/api/api.xsd">
<credentials token="12345678">
</credentials>
</Response>
var responseJson = xml2Json(responseBody);
var token = responseJson["Response"]["credentials token"];
postman.setEnvironmentVariable("token", token);
Answer the question
In order to leave comments, you need to log in
It turned out that the matter was in the format of parsing xml with the xml2Json function, the format is rather strange at the output, and the correct access to the token in this example looks like this:
var token = jsonObject["tsResponse"]["credentials"]["$"]["token"];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question