added api call for retrieving tokens, and fixes to support external api use