Finally got API working correctly