Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

REST POST to add attachment gives status 200 OK but no attachment is added to the issue (Cloud)


I'm trying to copy an attachment from a Jira-Software issue to a Jira-ServiceDesk issue (and the other direction as well) by using the ScriptRunner addon (script listener).

Basically I have the "linked issue key" on a text field, so when the attachment is added i get the linked issue by searching the issue with the key retrieved from this field and the attachments added from the event, create a multipartentity and use a /rest/api/3/issue/<issueKey>/attachments POST to upload them to the linked issue.

The issue here is, I get a 200 OK status response, but no attachment is added to the linked issue.

So far I'm testing this on a free instance, to be used on a client instance (I believe Standard plan if I'm not wrong)

The full code is as follows:


if(user.accountId == "557058:d2e5bd5c-dc49-41eb-a6f0-5e01093666c1"){return} //updated by a user different than the scriptrunner addon user
if(!changelog.items*.field.contains("Attachment")){return} //Only if there're attachments added.

import org.apache.http.entity.mime.MultipartEntityBuilder
import org.apache.http.entity.mime.HttpMultipartMode
import org.apache.http.entity.mime.content.ByteArrayBody

//ID of integrated projects
def jsmPrId = "10001" //Id of the JSM project
def jswPrId = "10000" //Id of the JSW project
//ID of customfields
def linkCfId = "customfield_10054" //id of the Linked Issue Key custom field

def linkedKey = get("/rest/api/3/issue/${issue.key}?fields=${linkCfId}")
.header('Content-Type', 'application/json')

def attachment
def fileBody
def multipart
for(i in changelog.items){
if(i.field == "Attachment" &&{
attachment = get("/rest/api/3/attachment/${}")
.header('Content-Type', 'application/json')

fileBody = get("${attachment.content.substring(attachment.content.indexOf('/secure'))}").asBinary().body

multipart = MultipartEntityBuilder
new ByteArrayBody(
new byte[fileBody.available()],

.header('Content-Type', "${}")
.header('X-Atlassian-Token', 'no-check')


Any ideas of why this is not working are more than welcome.

Also, testing this on Script Console (for a single attachment) gives a statuscode 200 OK and no attachment is added to the linked issue.


Actually there's another thing about this, if the attachment is bigger than certain contentLength it gives a contentLength too high error (I didn't measure this, basically it did throw the error with a .png file, but not with a test .pdf and a test .txt files)

Thanks in advance, kind regards,


3 answers

0 votes

I found in another answer that you have to set the name of the body part to the string "file". This works for me.

0 votes

I have this same issue. Very annoying, please fix.

0 votes

Hi @Alvaro Jardón 

It seems that the body is not valid for your API call and that is the reason why you are not to create the attachment. You will need to write your own custom script which gets the details of the attachment from the source issue and then calls the Add attachment API which is documented here to add each attachment to the required issue to copy it over.

Hope this will help you.

Thank you. 

Kind Regards


Hi Kate,

Actually that's what the script I posted does, get the attachment and call the add attachment api...

Also, how is it I get a 200 status code if it's not valid?

Thanks, kind regards,


It is unacceptable that Jira does not return an error status if it is not going to accept the request and act on it.

I'm having similar problems where .zip files are silently rejected by Jira. 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events