Forums

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

Jira cloud post function getLoggedUser returns Script Runner instead of user performing the transiti

Petru Simion _Simitech Ltd__
Atlassian Partner
July 8, 2025

I have a post function where I create an attachment and attach it to the issue.

The attachment contains information from assets.

In order to obtain the assets information I am using the assets API call this way:

I created a token and declared as def ASSETS_TOKEN = "xxxYYY..."

def auth = "<my personal valid email>:${ASSETS_TOKEN}".bytes.encodeBase64().toString()
def assetDetailsResponse = get("https://api.atlassian.com/jsm/assets/workspace/${workspaceId}/v1/object/${objectId}")
.header("Accept", "application/json")
.header("Authorization", "Basic ${auth}")
.asObject(Map)
.body
It works fine but I do not want the history in the issue to show always me as the one that did the attachment. So I tried replacing <my personal valid email> with Users.getLoggedUser().emailAddress. However the Users.getLoggedUser() returns Script Runner user, and not the user that triggers the post function. 
I tried the Authorization: Bearer ${ASSETS_TOKEN} but it returns 401 Unauthorized.
I tried curl, to test:


curl --request GET \
--url 'https://api.atlassian.com/jsm/assets/workspace/eaf0753d-5b96-4a5c-b99f-068797206587/v1/object/151' \
--header 'Authorization: Bearer XXXYYYZZZ...' \
--header 'Accept: application/json'

Throws 401 Unauthorized


curl --request GET \
--url 'https://api.atlassian.com/jsm/assets/workspace/eaf0753d-5b96-4a5c-b99f-068797206587/v1/object/151' \
--user 'validemail@somewhere.com:XXXYYYZZZ...' \
--header 'Accept: application/json'

Works fine

 

I believe the token to use with Authorization: Bearer has to be composed using the email of the user and the token.

 

Then I attach a file

def response = post("/rest/api/3/issue/${issueKey}/attachments")
.header('X-Atlassian-Token', 'no-check')
.header("Authorization", "Basic ${auth}")
.field("file", new ByteArrayInputStream(csvContent.getBytes()), "assets.csv")
.asString()
only shows how to code using the --user

 

So question is, how can this be fixed.

What I need is that the history shows as autor of the attachment change the user that performed the issue transition triggering the post function.

1 answer

0 votes
Utkarsh Agarwal
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 9, 2025

Hi @Petru Simion _Simitech Ltd__ 

In Cloud, post-functions run via the ScriptRunner app user context (not the user who triggered the transition), so Users.getLoggedInUser() (or getLoggedInUser() in Groovy) will return the ScriptRunner add-on account.

If you need to run actions as the real user, update the post-function settings to:

Run as → Initiating User

This ensures the script executes with the identity of the user who triggered the workflow transition, and getLoggedInUser() will return their account context.

If you're already doing that and still seeing the add-on user, it might be because the transition was triggered by automation or another app — in such cases, there's no actual user to impersonate.

Workaround:

If "Run as Initiating User" isn’t viable (e.g. due to app-based triggers), you can retrieve the last transition author from the issue changelog via the REST API:


GET /rest/api/3/issue/{issueKey}?expand=changelog

Look for the latest status change and extract the author.accountId field.

Kind Regards
Utkarsh

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events