Modified apiURL JavaScript method to use apply instead of call