In a REST script you cannot import libraries, so ideally you'd use a flow where there's your current fetch script and another step where you save it to state. The state is then tied to this specific flow path.
Is there a way to set a state of the app in use? I'd like to do an API call that gets a token, or receives the error from it, and then make it available to the app for future use.