Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

differentiate events initiated by api or gui

Mamikon Papikyan
Contributor
July 23, 2020

Hi I use scriptrunner in jira. I created listener with some functionalities, when issue created. If I create issue by jira gui  it works fine.
I have problem, when I create issue by api etc. (by python), my listener works again, but I don't want it. What solution will you suggest?

3 answers

1 accepted

0 votes
Answer accepted
Subrat Mishra
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2020

Try to differentiate your issues created by API and through GUI by some field value and use that as a condition in your listener to either skip or process . 

Example:

If you are using a BOT account for API , and create the issue with the BOT user as reporter , you can use that as a condition .

OR

In summary , have a prefix like [ Automation ] < summary goes here > for API created issues and use it as a filter .

Mamikon Papikyan
Contributor
July 23, 2020

Ok. Thank you so much!!! 

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2020

Hi @Mamikon Papikyan 

Or... rather than having two pieces of information in the Summary field (source and summary), consider using a different field to indicate the source, such as Labels, Components, or a custom field.  That will make searches, analysis, and updates easier in the future.

Best regards,

Bill

Like Mamikon Papikyan likes this
Mamikon Papikyan
Contributor
July 24, 2020

Hi @Bill Sheboy , thank you. This solution is nice too.

0 votes
Aayush Mohanka December 17, 2020

Thanks for the reply.

We have SSO configured were in, when an user logs in our app, he gets log-in in jira.
At that point of time, our API user and jira user are same.


0 votes
Aayush Mohanka December 16, 2020

How can I differentiate whether issueEvent raised is because of some transition made using UI or it is made by API call.
I need to make 3rd party call only when transition get updated by UI not by API

Subrat Mishra
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2020

Your api call must have a user-id . You can capture logged-in user name and compare if it's the api-user or an actual UI user .

 

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

def apiUser = "bot"

if ( currentUser == apiUser ){
// exit
}
else {
// execute 3rd party call
}

 

Aayush Mohanka December 17, 2020

if jira is logged in and API action is performed.
Will 

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

give actionable user?

Subrat Mishra
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2020

Your API user authenticates first and perform any action thereafter . Any action performed by that user can be captured as I mentioned above .

Aayush Mohanka December 17, 2020
String loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName();

It always return the logged in user and not the API user who performed action.
There are possibility, that jira is logged in and transaction is performed  with different user from the app, also name string of users can be same and it can be set of unknown that can't be hard coded as 

def apiUser = "bot"

Is there any call that clearly gives idea that this event creation is via a UI call?

Subrat Mishra
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2020

I'm not sure what do you mean by "Jira is logged in ". Jira will be logged in by many users at any given time , but above function will get you the user who performed the action (it can be api user or any other user).

 

If you run the above code in console , it will always return the user name you are currently logged in . If the same code gets triggered by an even it will return the api user which triggers that. 

 

getName() or getKey() gets you the user-id which should be unique . it's the getDisplayName() function that gets you the full name which can be many.

 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getKey()

 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName()

 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getDisplayName()

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events