How do I get the triggering user or device id in a workflow?

Sometimes, you'll need to know which device or user sent the event that triggered the workflow. Simply query any event using the Analytics library to retrieve the user id.  

 

Here's an example:

import Analytics
def get_API_user_id():
  last_event = Analytics.events('raw', limit=1)
    return last_event[0]["user"]