How to create issue in JIRA thorugh REST api?

I am sending a POST request to JIRA with my json data to create a project, but I cannot create a project in JIRA, I tried to see an error from Fiddler and I got the following error. I am using C # and the generated console app for it.

My JSON data that I am posting is as follows.

{
 "fields": {
     "project": {
         "key": "JTL"
     },
     "issuetype": {
         "name": "BUG"
     }
  }
}

      

Error message:

{"errorMessages": [], "errors": {"issuetype": "type type required"}}

I am sending json data from the following code, please suggest what and where am I wrong?

string data=@"{"fields":{"project":{"key":"JTL"},"issuetype":{"name":"BUG"}}}";

//object of HttpClient.
HttpClient client = new HttpClient();

//Putting URI in client base address.
client.BaseAddress = new Uri(uri);

//Putting the credentials as bytes.
byte[] cred = UTF8Encoding.UTF8.GetBytes("jiraUserName" + ":" + "JiraPassword");

//Putting credentials in Authorization headers.
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));

//Putting content-type into the Header.
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

//i am using StringContent because i am creating console application, no any serialize i used for maniputlate the string.
var content = new StringContent(data, Encoding.UTF8, "application/json");

//Sending the Post Request to the server. But getting 400 bad Request.
System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;

      

In the above code, you can see that I am sending credentials to authorize a user and submit data.

+3


source to share


2 answers


I solved my problem. I made small changes to my code and my code is working successfully. i changed url.

Old Url: https://MyCompany.atlassian.net/rest/api/2/issue
new url: https://MyCompany.atlassian.net/rest/api/latest/issue

      



in Json I made a small change, there was a Bug in the name of the "issuetype" which is currently not available in my account, currently the issue type "TASK" is available in my account, so I changed the name of isutype from "Bug" to " Task ". Now he works successfully! Thank goodness he killed a lot of time. Sadly: (

Thanks to Abdurrahman Koken too. :) Greetings!

0


source


Modify your details as shown below:



string data = @"{'fields':{'project':{'key':'JTL'},'summary':'Sample issue','description':'Creating an issue via REST API','issuetype':{'name':'Bug'}}}";

      

0


source







All Articles