Revert "Revert "Partial revert API query code""

This reverts commit 96f750c47ba6d426497395be5f952d778bc48a26.
Revert "Revert "Revert "Partial revert API query code"""

This reverts commit 6361df641ac24983a853493323a33475d945db23.