Fixed KeyError bug in api_pin()