Is there an API function do to this? Querying the database directly seems crude here.