NOTE: I'm trying to stay away from apex and see if I can do this all together with the flow. using apex I could create the rest endpoint in apex and invoke the flow from there and then return the response as I'd like to in apex like the following, and that's how I'm doing it right now, I want to see if I can avoid the apex code.
@RestResource(urlMapping='/my_flow')
global class MyApexAPI {
@HttpPost
global static void doPost() {
RestResponse res = RestContext.response;
try {
Map<String, Object> req = (Map<String, Object>) JSON.deserializeUntyped(RestContext.request.requestBody.ToString());
Flow.Interview.MyFlow myFlow = new Flow.Interview.MyFlow(req);
myFlow.start();
res.responseBody = Blob.valueOf(String.valueOf(myFlow.getVariableValue('response_message')));
res.statusCode = Integer.valueOf(myFlow.getVariableValue('response_status'));
} catch (Exception e) {
res.statusCode = 500;
res.responseBody = Blob.valueOf(e.getMessage());
}
}
}