Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have an issue i think it is not with the json.

When i used the same json in the postman application, everything worked fine.

im trying to post through my winform programs in C#. Below is my code.:

public void createIssue()
       {

           string data = "{'fields': {'project':{'key': 'RSSPSI'},'summary': 'Test','description': 'TESTING','issuetype': {'name': 'Staging Installations'},'customfield_10807': '2018 - 09 - 19T10: 00:00.000 + 0000','customfield_15924': [{'value':'TEST 10'}],'customfield_11201': {'value':'RS2SP'},'customfield_16000': 'API TEST','components': [{'name':'System Engineer'}]}}";
           using (var client = new HttpClient())
           {
               client.BaseAddress = new Uri("https://LINKTOJIRA/rest/api/2/");

               byte[] cred = UTF8Encoding.UTF8.GetBytes("username":" + "password");

               client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
               client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

               var content = new StringContent(data, Encoding.UTF8, "application/json");

               System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;
               Console.WriteLine("Create Issue Response : \n" + response);
           }




       }


What I have tried:

I tried to check if the json is wrong or not but in postman app, everythign worked fine so maybe im doind something wrong with the request ?
Posted
Comments
littleGreenDude 20-Sep-18 8:42am    
Two things; the byte[] cred = UTF8Encoding.UTF8.GetBytes("username":" + "password"); looks odd to me, and is there any additional information included in the response? If you look at the following URL

https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-createIssue

a 400 response typically contains additional information indicating if you missed a required field.
littleGreenDude 20-Sep-18 8:45am    
Alternately, you may want to try posting to https://LINKTOJIRA/rest/api/latest/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900