Home > Back-end >  Post an attachement to jira c#
Post an attachement to jira c#

Time:03-01

I am trying to post an attachement to JIRA but getting a 404 http error .

I did post some comments before and it's working fine.

MY Code below

                string jsmlogin = "****";
            string jsmpass = "****";
   string _auth = string.Format("{0}:{1}", jsmlogin, jsmpass);
            string _enc = Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth));
            string _cred = string.Format("{0} {1}", "Basic", _enc);
            string projKey = "DESK-1993";


            string postUrl = "https://******/rest/servicedeskapi/request/"   projKey   "/attachments";
            string jsmproxy = "http://********";
           
            
             var clientHandler = new HttpClientHandler();
            clientHandler.Proxy = new WebProxy(jsmproxy, true);
       
           HttpClient client = new HttpClient(clientHandler);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _enc);
            client.DefaultRequestHeaders.Add("X-Atlassian-Token", "nocheck");
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            MultipartFormDataContent content = new MultipartFormDataContent();

           HttpContent fileContent = new ByteArrayContent(File.ReadAllBytes("z.txt.txt"));
           content.Add(fileContent, "file","z");
             var response = client.PostAsync(postUrl, content).Result;
     
             

CodePudding user response:

I think you get a 404 cos the url is not correctly formed...

The url for the POST should look like

 http(s)://{base-url}/rest/api/{apiVersion or latest}/issue/{issue-key}/attachments

for me your /request/ part looks weird and should be issue

here the doc: https://docs.atlassian.com/software/jira/docs/api/REST/8.22.0/#issue/{issueIdOrKey}/attachments-addAttachment

  • Related