full remove duplicate code from api_connection