Fixed problems caused by the API returning errors.

Also refactored API endpoint url.