Someone just reminded me that you could also use script variables - these are already supported by the API.
So you could change your script to outout data into a script variables and then read that via the existing API call.
Note that the API only returns Strings so you would need to parse the result.
Theres also going to be a size limit although I cant remember what that is offhand.
Cheers,
Simon