How can I copy a non Json text response to a Variable in the tests

How can I copy a non Json response to a Variable in the tests
I have just done it to the console to see if I can get the info to at least show there

I have tried a lot of different ways a few of the json.parse but I then get a JSON error

JSONError: Unexpected token ‘e’ at 1:1 or “undefined” for the non JSON ways

How I found the problem
Run a request and then tried to copy the body of the response (which is a token) to a environment variable.

I’ve already tried:
I have looked around on different ways (most are for JSON)
On how to do this but they all come back with an error or with “undefined”

Hey @fenwickr

To get the value of a non JSON response, you would use pm.response.text().

Once you have that you that, you can use some basic JS to extract different parts of the value if needed.

Thanks work perfectly - When I tried that I was missing the () after the text

1 Like