Modular Workflows? - Setting Up API Connector

Could anyone point me in the right direction when it comes to connecting to an API that requires to make a call to create a ‘session’ which returns a token. Then using that token on subsequent calls.

I have successfully made the connections (and created API calls within the API connector plugin) and they all work. I can map the 3 basic calls for sessions (create, test, close) to buttons by making workflows for each. My questions is about how do I create some logic that tests the session, and then decides to create a new one or not then move onto sending the data. It feels clunky to be doing that in every workflow where I want to send data to this API and so I wondered if that should be stored in a ‘API Workflow’ which can be called from the initial workflow.

I haven’t found how to modularise code in Bubble where you write it once, then call it when you need it. Is that possible?

If so I can then have a workflow that wants to write some data but envokes the workflow that tests and creates the connection first, then after that is successful it sends the data to the API.

Am I missing something?