Refresh Bearer Token

Hey all!
I’m trying to make a pack that targets an API that requires me to make a daily bearer token.
I can’t seem to find how to do this in the docs though.
The bearer is returned after I call an API with credentials, but they aren’t OAUTH, just spawned credentials in the app.

Hi @Hartland_Brown - Welcome to the Coda community! The only token exchange protocol that Coda has built in support for is OAuth2, but there is a workaround that I’ve used a number of times that you could try.

  1. Select an auth type that works for the endpoint that generates the bearer token.
  2. At the start of every building block’s execute function, call a helper function that uses those credentials to fetch a bearer token. (Tip: Set a cacheTtlSecs on that request so that the resulting token is cached.)
  3. Manually add that token to the outgoing request and suppress the actual auth using disableAuthentication: true.

If you can point me to the docs for the API you are trying to call I can give you some more concrete advice.

You can see an example of that pattern in my Visualping Pack:

The getToken() function is defined here:

Amazing thank you Eric!
I’ll give this a try!

1 Like