Queries and helper functions for export to API