Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

How can I send an attachment from Jira to a REST API using ScriptRunner (Groovy script)

Dear Community,

Below is my Use case:

I am trying to send an attachment and the Issue/Ticket details from Jira Service Desk(Server) using ScriptRunner plugin ( Groovy script) to a Third-party REST API.


Using the below code to send the attachment in the request, but I am getting "stackOverflowError". How to resolve this issue and achieve the goal here?

Please advise.


def issueManager = ComponentAccessor.getIssueManager()
def aM= ComponentAccessor.getAttachmentManager()

Object obj;

List attachments = aM.getAttachments(issue)

if (!attachments.isEmpty()) {
for (Attachment a in attachments) {
String fileName=a.getFilename()
attachmentID = a.getId()

obj = aM.getAttachment(attachmentID)



def body_req = [
"consumerCode": "abc",
"metaData":[ "title":issueID,
"type": "attachment"
"document": (obj!=null)?obj:null,
"file" : null


def baseURL = "http://localhost:XXXX/upload/jiraAttachmentLetter";

URL url;

url = new URL(baseURL);

HttpURLConnection connection = (HttpURLConnection) url.openConnection()
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }


Please advise.

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

Security Advisory for Jira Service Management

On October 20, 2021, Atlassian published a security advisory for Jira Service Management. The full advisory is available at this link.  We've seen a number of questions already asking for...

307 views 1 2
Read article

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