Better handling of custom API Query

@stephanfowler