api_query function

Wrapper for sending queries and payloads to API