Add function to API
Fix errors