Getting JSON data into app variable

Hi there!

I’m using an HTTP request to authenticate users via an external system. The response is JSON and includes a refresh token. I’d like to store that refresh token as an app variable so I can use it on each page.

First question, am I thinking about that in the right way?

Second, I’m having trouble storing it into the app variable. I’m using the “Set app variable” function following the HTTP request. I’m using the Formula method to set the value.

My formula looks like this:

LOOKUP(outputs["HTTP request"].resBodyRaw,"refresh_token")

I get this error: “Text type is not assignable to object type”

I’ve also tried it with:

LOOKUP(outputs["HTTP request"].resBodyParsed,"refresh_token")

In that case, I get this error: Type “json” is not assignable to object type AND Type “json” is not assignable to text type.

Seems like this should be pretty simple.

What am I missing here?

P.S. I’m confident I’m getting good data back from the HTTP request. I flowed it into a Javascript snipped and used alerts to verify what was coming back.

1 Like

outputs["HTTP request"].resBodyParsed["refresh_token"]+""

Example:

https://jsonplaceholder.typicode.com/todos/1

ENCODE_JSON does not accept json type, but it accepts list type:
SUBSTRING(ENCODE_JSON([outputs["HTTP request"].resBodyParsed['userId']]),1,-1)

Or just append empty string:
outputs["HTTP request"].resBodyParsed['userId']+""

1

1 Like

That worked perfectly! Thanks @dwidge

One thing I noticed is that the LOOKUP I used above didn’t work in my browser preview. But when I used the preview app on my phone, it did work. The solution you provided works for both.

Thank you!

1 Like

Estava a dias procurando esta solução, muito obrigado, excelente post, salvou meu final de semana.