How can I save a Rest API response as a variable?

Hello, I have one api request that retrieves me an access token, I would like to save that token as a variable so it can be used in subsequent requests. I've tried to use the "transform results" section of the request but without luck. I don't know JS so have been trying with chat gpt, not helpful..

The response is as follows:

{
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIwMkg5NkZIIiwiZmlybUlkIjoiTU9ORVZURhdGUiOiIyMDI0LTA1LTEzVDEzOjQyOjQwLjU5NFoiLCJpYXQiOjE3MTU2MDc3NjAsImlzcyI6IlNlY2NsVUkiLCJqdGkiOiJiNGZlYmFhYS0zZGYxLTQ2NTItODZmYy1jODZiNDkzZmI2YzAifQ.dUA0LXGsrp091Q3IWDjkHs2WHfEquSkHwJPbXOcfqLo",
    "userName": "Joao",
    "userType": "User"
}```

I've created a variable, but what should I add on "Transform results" so the token is saved?

Thank you for the help!
1 Like

It’s already saved in the query.data object, which you can reference from other components.

If that’s the raw response you posted then you’ll need to use query.data.data.token to reference it.

3 Likes