Code for the API events.