I've followed the instruction and tried the curl example at https://docs.atlassian.com/jira/REST/latest/#id102824. However, I'm getting "Unauthorized (401)" error. So is the example wrong, or am I missing something? Thanks!
BTW, other REST API calls (creating and updating Issue) work fine.
Community moderators have prevented the ability to post new answers.
Hi Paul,
Can you kindly try to run the following cURL command and see if it helps?
curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@das.txt" http://localhost:8082/jira1/rest/api/2/issue/MP-1/attachments
I have tested the cURL command, and it works on my end. However, kindly note to change the username/password, filename, and your instance URL as needed.
If the problem remains, that you still get the HTTP 401 error, then can you kindly try to add the attachment to other issue? This is to confirm that the problem is not related to Create Attachments permission, in the permission scheme associated to the project.
I hope that this will help!
THIS CODE WORKS
public class JiraRest {
public static void main(String[] args) throws ClientProtocolException, IOException
{
String pathname= "<Full path name of the attachment file>";
File fileUpload = new File(pathname);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost("URL+Post REST API");
BASE64Encoder base=new BASE64Encoder();
String encoding = base.encode ("username:password".getBytes());
postRequest.setHeader("Authorization", "Basic " + encoding);
postRequest.setHeader("X-Atlassian-Token","nocheck");
MultipartEntityBuilder entity=MultipartEntityBuilder.create();
entity.addPart("file", new FileBody(fileUpload));
postRequest.setEntity( entity.build());
HttpResponse response = httpClient.execute(postRequest);
}
}
Required JARs:
All JARs in lib folder of httpcomponents-client-4.5-bin and sun.misc.BASE64Decoder.jar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
@[deleted]
I am getting internal server 500 error,as below
HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Date: Mon, 24 Dec 2018 14:04:46 GMT, Access-Control-Allow-Credentials: true, Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT, HEAD, Access-Control-Allow-Headers: Content-Type, Content-Length: 379, Connection: close, Content-Type: text/html; charset=iso-8859-1] ResponseEntityProxy{[Content-Type: text/html; charset=iso-8859-1,Content-Length: 379,Chunked: false]}}
Please help.
Thanks
Divya Srinivasan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used the same code and getting response as 500 - Internal Server Error as below:
HttpResponseProxy{HTTP/1.1 500 [Server: Atlassian Proxy/1.13.6.2, Vary: Accept, Cache-Control: no-cache, no-store, no-transform, Content-Type: application/xml;charset=UTF-8, Strict-Transport-Security: max-age=315360000; includeSubDomains; preload, Date: Fri, 22 Feb 2019 10:08:20 GMT, ATL-TraceId: f5f5bc636e82f862, X-AACCOUNTID: 5c4f0a271487971712d6c762, X-AREQUESTID: b2d64877-b821-47ea-934d-02a18e5f05c9, X-XSS-Protection: 1; mode=block, Transfer-Encoding: chunked, Timing-Allow-Origin: *, X-AUSERNAME: admin, X-Content-Type-Options: nosniff, Connection: close, Set-Cookie: atlassian.xsrf.token=727a24c6-407f-417d-abc1-dd8d50087063_7fe1286fea3d08fc055dc4441b8fffb1ec736dba_lin; Path=/; Secure] ResponseEntityProxy{[Content-Type: application/xml;charset=UTF-8,Chunked: true]}}
Can you please help me out.
Thanks,
Soujanya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the same directory you ran curl from
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.