Add a check if `api_result` exists before getting its length.