Update docstrings in haas/api.py
Factor out common SQL query