Forums

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

SOLVED: attach a file using REST from scriptrunner

Derek Fields _RightStar_
Community Champion
June 13, 2019

I have created a very simple test script to figure out how to attach a file to an issue. The "file" is actually just text that I want to create a file. Since this is in the Cloud, I am assuming that I can't write the file to a temp file in order to import it.

import org.apache.http.entity.ContentType;
String text = "This is a simple set of text"


def response = Unirest.post("/rest/api/3/issue/CDFT-1/attachments")
.header("Accept", "application/json")
.header("Content-Type", "text/plain")
.header("X-Atlassian-Token", "no-check")
.field("file", text.getBytes(), "text.txt")
.asJson();

I get a 415 - Unsupported Media Type error from this. Any help is welcome

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ravi Sagar _Sparxsys_
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 Champions.
October 24, 2019

Hi @Marcela Junyent 

Where are you running this script? and can you share the link from where you copied it?

Thanks,

Ravi

Marcela Junyent
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 Champions.
October 24, 2019
TAGS
AUG Leaders

Atlassian Community Events