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?

Since it's a method I also prefer it raise an exception rather than just exit.