It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

REST call as current user

Hello, my goal is to get all possible information about the current issue and send it by e-mail.

The only thing I came up with is getting it from REST (similar to the way it is done when calling webhook in the post function)
The code below gives me a json wich I can email.

But I dont like to store a user credentials in a script. Can I somehow execute that REST call with a currently logged in user? The way it is done when calling a webhook (I mean that when I call a webhook in a postfunction it done with a current user credentials).

 

import groovy.json.JsonSlurper
import org.apache.commons.io.IOUtils

def user = "user"
def password = "passwd"
def urlConnection = new URL("http://jiratest.dom.com/rest/api/2/issue/ISS-56905").openConnection()
urlConnection.setRequestProperty("Authorization", "Basic " + (user + ":" + password).bytes.encodeBase64().toString())

def jsonString = IOUtils.toString(urlConnection.inputStream)

 Jira 6.2.4

ScriptRunner 3.0.16

1 answer

1 accepted

0 votes
Answer accepted

There might be a way, but I don't know it.

But you could get all the information from a jira issue using the JAVA api.

You could start with something like this and refine the output as needed (for example, expand user type fields).

import com.atlassian.jira.component.ComponentAccessor 
def cfm = ComponentAccessor.customFieldManager
def im = ComponentAccessor.issueManager
def issue = im.getIssueObject('JSP-1922')

def issueMap = [key:issue.key, id:issue.id, fields:[]]
issueMap.fields << [summary: issue.summary]
issueMap.fields << [description: issue.description]
issueMap.fields << [assignee: issue.assignee]
issueMap.fields << [reporter: issue.reporter]
cfm.getCustomFieldObjects(issue).findAll{issue.getCustomFieldValue(it)}.each{
issueMap.fields << [(it.name) : issue.getCustomFieldValue(it)]
}
issueMap

Hello Peter,
Thank you for your help. Your suggestion will do the trick, and I think I'll stick to it for now because it's the best solution for now.

 

The only thing there is a little mistype at "def issueMap" "fields" should be a LinkedHashMap instead of ArrayList. :)

def issueMap = [key:issue.key, id:issue.id, fields:[:]]

 

Thank you :)

It wasn't a mistype... I just didn't look a the rest output structure close enough.

The array would work took, it just makes finding and accessing individual field items a little harder.

Clearly the map is better.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you