osascript provides a simple way to grab the bundleid of an app in macOS. Simply use -e and then single quote id of app with the app in double-quotes. And viola:
osascript -e 'id of app "Audacity"'
The output will be as follows:
org.audacityteam.audacity