You should also check if `api_result` exists before trying to access it.