Refactors APIHandler:callAPI

Refactors and optimizes the APIHandler->callAPI.
Merge pull request #1968 from KenanSulayman/patch-1

Refactors APIHandler:callAPI