I would use Forge Storage. It’s a persistent key value store for Forge and it seems like it’s exactly what you need.
For your external tool, you will need to push the data to it from Forge. For example, a REST call when the user submits the form. There is currently no way for you to retrieve data from Forge storage outside the context of your Forge app (that I am aware of).
You can not persist Macro data from the macro view, only from the editor. This is a security constraint. You can post the data to your own function and store the data in Forge Storage, as also mentioned by @Ryan, but there is a tricky part to this as it is difficult to link said data in storage to a specific Macro. Confluence does have macro IDs, which you should be able to retrieve from context, but those macro ID’s are not persistent. A macro ID can change when a page is edited.
There is no easy solution to this. Your best bet is to require some sort of initial macro editing, in which you put a placeholder form ID in the macro data and store all form entries against that form ID. That is the only way to have a persistent identifier for that specific macro in your database.
Actually the data for the individual macros are stored in bitbucket,
The issue is that there will be multiple Macros on the page that need to access the same data.
i.e. there will be a Macro form, some user editable data, another macro form etc.
Each Macro form will have a unique entry in the data structure.
I really only want to get the data once when the page loads, and save/commit it after the forms have been populated.
To do this I think I need to create a new macro which loads the forge storage from bitbucket, and then my other macro instances can access it from there.
This is all a bit convoluted, but I am constrained by other users who want to be able to edit the content between Macros in a specified manner, If it was text only I’d just pull all the data into bitbucket, but unfortunately we need to support images too.
I too am working on a macro that needs a persistent macro id, even on save. @remie Is there really no way for the macro to create a unique identifier when first created and to save it?