I wonder if this kind of stuff should be factored out of the API code and placed into it's own file?  My general dividing line for this is whether or not the code is doing primarily API things or business logic things.  This seems more like business logic.  Not a show stopper for sure, but worth thinking about.  I think there are several similar pieces of code in the API.  I'd like us to keep a clean separation between the API and the business functionality if we can.