update api example to be more robust