# Example bash script to identify who triggered a workflow

**URL:** <https://discuss.circleci.com/t/example-bash-script-to-identify-who-triggered-a-workflow/37876>\
**Category:** API\
**Created:** [October 22, 2020, 8:12pm UTC](https://discuss.circleci.com/t/example-bash-script-to-identify-who-triggered-a-workflow/37876 "2020-10-22T20:12:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaryt](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jaryt/32/24066_2.png) [@Jaryt](https://discuss.circleci.com/u/Jaryt)\
**Post date:** [October 22, 2020, 8:12pm UTC](https://discuss.circleci.com/t/example-bash-script-to-identify-who-triggered-a-workflow/37876/1 "2020-10-22T20:12:13Z")

</div>

Hello Everyone!

Recently the Support team created a script for determining who triggered a workflow by using our v2 API. Feel free to mix up the script how ever you best see fit!

_Note: We’re making us of `jq` which makes using JSON in scripts possible_  
_Also, if you have an environment variable set with your CIRCLE\_API\_TOKEN, feel free to delete the variable declaration line from the script!_

```auto
#!/bin/bash -e

# This script will return the user who started a workflow
# Can be called with "sh name_of_file.sh" -- you will be prompted for a workflow ID to get data on

### Variables ###
​
# Set to personal API token
CIRCLE_API_TOKEN=
​
### Commands ###

# Check for Input
read -p 'Workflow ID: ' WORKFLOW
​
if [-z "$WORKFLOW"]
  then
    echo "No argument supplied, please enter a workflow ID."
    exit 1
fi

USER_ID=$(curl https://circleci.com/api/v2/workflow/$WORKFLOW?circle-token=$CIRCLE_API_TOKEN | jq -r '.started_by')

curl https://circleci.com/api/v2/user/$USER_ID?circle-token=$CIRCLE_API_TOKEN
​
#### END ####

```

---

<div class="post-metadata">

**Author:** ![owenjoliver](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/owenjoliver/32/28293_2.png) [@owenjoliver](https://discuss.circleci.com/u/owenjoliver)\
**Post date:** [April 26, 2022, 3:00pm UTC](https://discuss.circleci.com/t/example-bash-script-to-identify-who-triggered-a-workflow/37876/2 "2022-04-26T15:00:07Z")

</div>

Closed on April 26, 2022, 3:00pm UTC


