Implemented (roughly) the api call