Added error checking on the API calls to verify that they are successful and exit the script appropriately