Forums

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

Send Jira attachment via REST post request to an another application

Aswin Dharmaraj October 10, 2022

I want to send all the issue attachments to an external service via REST post call. Any scripts this can be achieved?. Simply I want to send the attachments when in an issue attachments were added.  The endpoints already provided by the external team need to send the form-date as files. Anyone please help me on this.

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 11, 2022

Hi @Aswin Dharmaraj

Could you please clarify what is the external service you are referring to? Is it Confluence?

Thank you and Kind regards,

Ram

Aswin Dharmaraj October 11, 2022

External service its a stand alone application if we create a jira issue same will be created in that application. we need to send the attachment updates to then using the REST end point they provided. But we are stuck with the scripts that to get the attachments from jira and send via a http request.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 11, 2022

Hi @Aswin Dharmaraj

If you intend to send a REST Request (whether it is GET, PUT, POST, or DELETE) to an external service, you need to do something like this example provided in the Adaptavist Library.

Using the REST Endpoint will not work for this. You could, however, try with the Listener, i.e. using the Issue Updated event. 

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Aswin Dharmaraj October 11, 2022

Yes Ram, I was working on listener script only but the requirement to send the attachment, looking for a code that will fetch the attachment from Jira and send via POST request. How to construct a post request for form data and include the file in it. Some sample script I was working on now.

 

def client2 = new HTTPBuilder( 'URL ' )
client2.request ( POST, JSON ) { req ->
    uri.path = '/file'
    headers.'Authorization' = "Bearer ${accessToken2}"
    contentType = form-data
    setHeader("X-Atlassian-Token", "nocheck")
    MultipartEntityBuilder entity = MultipartEntityBuilder.create()
    entity.addPart("file", "path")
    setEntity(entity.build())
    body = fileEntity.build()
    response.success = { resp, json ->
     log.debug("Token response: " + JsonOutput.toJson(json))
       response2 = JsonOutput.toJson(json)
 }
    response.failure = { resp ->
        log.warn("response code is : " + resp.status.toString())
    }
    response.success = { resp, json ->
      log.info("Resp status " + resp.status.toString())
    }
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events