Updated API connection script