Prevent pre-transition script from running for API user

I have a pre-transition script below that sets a javascript var for FromState.  However when this runs for an API we have setup for an integration it fails.

How can I catch this in the script and prevent it from running because it is not needed for the API?

...script...

If Ext.ShellHasProp( "Item" ) Then
   Call Ext.WriteStream("<script type='text/javascript'>var myFromState = '" & Shell.FromStateName & "';</script>")
end if

When this runs for my API account I get this in Event log...

Error occurred in file:
'd:\bld\bm_mainline\bm_mainline-aex64\application_engine\software\teamtrack\source\process\slerror.cpp', line 310.
User: Id 93592, 'VailCerner API'

RUNTIME ERROR IN SCRIPT "CM-SetFromState" (id=87)
(called from pre-transition context)

SBM AppScript output stream unavailable. -- ERR #21

Line 2> Call Ext.WriteStream("<script type='text/javascript'>var myFromState = '" & Shell.FromStateName & "';</script>")