I'm trying to grab data from my response in Bruno and set it to the environment variable called bearer_token. Here's the issue. The response is raw and is just the bearer token. So, I'm not sure what I'm supposed to do to parse the raw response without a body. I have tried to use just res as the data and setting this as the bearer token, but when I check my response, low and behold, the environment variable is still blank. I have attached my Post Response script (the one given by the Bruno documentation), and it doesn't work. Any suggestions would be appreciated.
function onResponse(res) {
let data = res.getBody();
bru.setEnvVar("bearer_token", data);
}
Your token is generally a key of your data object and not the "data" itself. In the "Post Response" field of the Script section, the following script should work:
let data = res.body;
bru.setEnvVar("token", data.access_token);
This is the answer if it's just a response without any other key-value pairs, but just the bearer token as a response.
let data =res.body ;
bru.setEnvVar("token",data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With