How to update an environment variable in function?

Options

Hey! How do I update an environment variable in the function stack?

I'm using a GET request with the Spotify API, and my access token expires every 60 minutes.

I designed my stack to request a new access token. If a 401 code is received, an If condition request a new token, and the request is rerun with the new one.

It is working well, except that every time the original request is run, it is with an expired access token causing the stack to request a new token on every call.

I only want to request new access tokens as they expire.

I had an idea to use an environment variable containing the active token in the original call and update it via the stack once a new one is received.

Unfortunately, I don't see a way to update an environment variable within a function stack.

Is this possible, or do I need to take a different approach? If a new direction, what would that be?


Best,

Answers