Forums

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

400 Bad Request When Creating Issue via Jira Rest API

Khushbu Trivedi March 15, 2018

string data = @"{""fields"":{""project"":{""key"": ""md""},""summary"": ""reset example"",""description"": ""creating an issue via rest api"",""issuetype"": {""name"": ""bug""}}}";
//string postUrl = "https://aconline.atlassian.net/rest/api/2/issue/";
string postUrl = "https://aconline.atlassian.net/rest/api/2/issue";
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();

client.BaseAddress = new System.Uri(postUrl);
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"));

System.Net.Http.Formatting.MediaTypeFormatter jsonFormatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter();
//< Issue & gt;
System.Net.Http.HttpContent content = new System.Net.Http.ObjectContent<string>(data, jsonFormatter);
//var content = new StringContent(data, Encoding.UTF8, "application/json");
System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;
if (response.IsSuccessStatusCode)
{

//descrptiontextBox.Text = result;
ViewData["Result"] = response.Content.ReadAsStringAsync().Result;
}
else
{
//descrptiontextBox.Text = response.StatusCode.ToString();
ViewData["Result"] = response.StatusCode.ToString();
}

1 answer

1 accepted

0 votes
Answer accepted
Alexey Matveev
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 Leaders.
March 15, 2018

Have a look at the response message, which Jira returns. There will a detailed explanation of your error. Or install Rest Browser plugin and execute your rest method there. You will see the error.

Khushbu Trivedi March 15, 2018

Thank you for response this get resolved :) 

Suggest an answer

Log in or Sign up to answer