How to pass value from json response into another resource query

Hi All , I'm trying to get a mobile app we have built in retool to speak to one of our main web applications.

Our web application has a web api which i have been learning how to use , using postman.

I've successfully built a resource in retool that connects to this API and then gets an authorised token with an expiry on.

I need to use this token in any queries i then use to prove I'm authenticated.

Heres where i need your help whats the best way to do this, how do i pass a value that I'm getting in a json response into another resource into a query within my app?

here is the response message

so id like to then run a query from retool that for example writes data back to the api and i will need this token and also to check that it is still valid

any help is greatly appreciated.

Hi @phillipi - you can make use of Retool variables. You can create a variable, let's say myToken, and a JavaScript query setMyToken that sets it's value. This JS query may look like this:

//these few lines parse token from xml string from your screen shot image
const regex = /<a:Token>(.*?)<\/a:Token>/;
const stringWithToken = queryThatReturnsToken.http2.body.rawXml;
const match = stringWithToken.match(regex);
const token = match ? match[1] : "";

await myToken.setValue(token)

You may want to update queryThatReturnsToken by adding success handler that triggers the above query.

Once you have myToken value you can use it in other queries like this: {{myToken.value}}

Hope this helps!