I'm trying to quit an application with an AppleScript by providing its bundle identifier.
My code does not work:
tell application "System Events" to quit (application whose bundle identifier is "com.apple.Notes")
or
quit app "com.apple.Safari"
Your second snippet is pretty close, you need application id
quit application id "com.apple.Safari"