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()
log.warn(fileName)
attachmentID = a.getId()
log.warn(attachmentID)
obj = aM.getAttachment(attachmentID)
}
}
def body_req = [
"consumerCode": "abc",
"ticketNumber":issueID,
"documentTitle":"Attachment",
"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.setRequestMethod("POST")
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();
*******************************************************
Please advise.