ahucks
July 19, 2024, 6:12pm
1
I'm stuck on this.
I'm authenticating to my REST API and getting an access token back. How do I save that token to be used in queries?
In my queries, I'm thinking that I'll do something like:
Here's my auth workflow:
Any pointers are appreciated.
pyrrho
July 19, 2024, 6:29pm
2
Hello!
You don't need the curlies {{ }} in the variable being used in the resource headers.
Bearer {{ accessToken }}
==> Bearer accessToken
should work.
ahucks
July 19, 2024, 6:50pm
3
Thanks for the reply!
When I do Bearer accessToken in the query, the API request shows:
{
"request": {
"url": removed,
"method": "GET",
"body": null,
"headers": {
"User-Agent": "Retool/2.0 (+https://docs.tryretool.com/docs/apis)",
"Authentication": "Bearer accessToken",
}
},
"response": {
"data": {
"detail": "Authentication credentials were not provided."
},
}
}
I reauth prior to running the query.
Update:
Should've been using Authorization instead of Authentication. I'm at least getting a different response from my API:
{
"detail": "Given token not valid for any token type",
"code": "token_not_valid",
"messages": [
{
"token_class": "AccessToken",
"token_type": "access",
"message": "Token is invalid or expired"
}
]
}
When I replace Bearer accessToken
with the actual token, it runs fine - as expected. So still just the problem of passing the accessToken from the auth resource.
pyrrho
July 19, 2024, 7:23pm
4
Can you show a screen shot of your re-authorization flow?
I am wondering if it is setting the same variable with the newly refreshed token response.
ahucks
July 19, 2024, 7:38pm
5
I haven't set up the re-authorization work flow yet.
If I had access to the refreshToken
in the steps in my OP, it'd just be passing:
{
"refresh": "{{ refreshToken }}"
}
and then setting accessToken
to the new access token in the JSON response.
Edit: My comment about "I reauth..." is just clicking the Re-auth button in the query setup window.
Edit2: Had a typo in my header that happened after fixing the {{ }}
Refresh seems to be working, I set it up as described above...also without the {{ }}
Thank you!
1 Like