Added a function for API calls

I'm a bit unsure if the raise ValueError is appropriate here (Instead of just sys.exit as it was before).
What do you think?