Forums

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

Groovy to upload attachment

Reeja Mathews July 11, 2022

Hi - 

Below is the documentation I see for 'POST request to upload attachment'. Is there a groovy code, that is available for 'upload attachment' ?

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post

2 answers

0 votes
Reeja Mathews July 14, 2022

Hi all, any update to this question.. 

0 votes
Craig Nodwell
Community Champion
July 12, 2022

Hi @Reeja Mathews welcome to the community.  There is groovy code to achieve this and it is used within plugins such as Scriptrunner or Groovy for Jira.  Do you have any of these plugins available to you?  

Reeja Mathews July 13, 2022

Yes, I tried the below. It says 200, but doesn't really attach anything to Jira, any idea where I might be going wrong ?

 

// ------- CODE --------

def args = [
httpMode : 'POST',
url : "https://<url name>/rest/api/2/issue/PEQT-234/attachments",
customHeaders: [
[maskValue: true, name: 'Authorization', value: "Basic xyz="],
[maskValue: false, name: 'X-Atlassian-Token', value: "no-check"],
[maskValue: false, name: 'Content-Type', value: "multipart/form-data"]
],
uploadFile : 'README.md',
wrapAsMultipart : true,
multipartName : 'README.md'
]

httpRequest args

// ------- CODE --------

 

I tried with content-type as 'application_json' too, but doesn't do an upload properly

fyi - masked the url name and the basic authorization

Reeja Mathews July 15, 2022

hi @Craig Nodwell Please let me know where I could be going wrong, when you get a chance. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events