Forums

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

How to send list of issue attachments from automation to external source via api

Kate September 9, 2025

Dear All,

 

Please help. I need to send list of attachments as a String to external source.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.attachment.Attachment
import groovy.json.JsonOutput
import java.net.HttpURLConnection
import java.net.URL


def issue = issue
def attachmentLink = ""
def apiToken = "______________________________________"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

def attachmentManager = ComponentAccessor.getAttachmentManager()
List<Attachment> attachments = attachmentManager.getAttachments(issue)

attachments.each {attachment ->
    attachmentLink += "_____________________________________________________________"
}

def getCustomFieldValueById({{issue.customfield_16600}}) {
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def customField = customFieldManager.getCustomFieldObject(fieldId)
   
    if (customField) {
        return issue.getCustomFieldValue(customField)
    }
    return null
}

getCustomFieldValueById()

def updateContext(elmaAppId, attachmentLink) {
    def elmaUrl = "________________________________________________"
    def payload = [
        ssylka_na_dogovor_tkp: attachmentLink
    ]
    def url = ner URL(elmaURL)
    def connection = url.openConnection() as HttpURLConnection
    connection.requestMethod = "POST"
    connection.doOutput = true
    connection.setRequestProperty("Authorization", "Bearer ${apiToken}")
    connection.setRequestProperty("Content-Type", "application/json")
    connection.setRequestProperty("Accept", "application/json")
   
    def outputStream = connection.outputStream        
    outputStream.write(JsonOutput.toJson(payload).getBytes("UTF-8"))
    outputStream.flush()
    outputStream.close()
   
}

updateContext(getCustomFieldValueById(), attachmentLink)

 

1 answer

0 votes
Marc - Devoteam
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.
September 9, 2025

Hi @Kate 

It seems you are using scriptrunner.

I'm not a scripter, but thus blog article might help, send-email-with-attachments-stored-in-the-jira-issue-with-scriptrunner/ 

Or reach out to scriptrunner support, to provide you with help on this request.

Suggest an answer

Log in or Sign up to answer