Adjusted API query code