Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

400 Bad Request When Creating Issue via Jira Rest API

Moshiur Rahman June 26, 2014
I was able to get editmeta using issue id. But when I am trying to create issue using Jira Rest API I am getting (400) Bad Request. I also tried with project key. Sample code:

string data = "{\"fields\":{\"project\":{\"id\":\"15320\"},\"issuetype\":{\"id\":\"25\"},\"summary\":\"Test\",\"description\":\"Test Desc\",\"priority\":{\"id\":\"2\"},\"versions\":{\"id\":\"33157\"}}}"; string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString()); if (argument != null) { url = string.Format("{0}{1}/", url, argument); } HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.ContentType = "application/json"; request.Method = method; string base64Credentials = GetEncodedCredentials(); request.Headers.Add("Authorization", "Basic " + base64Credentials); if (data != null) { using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(data); } } WebResponse response; try { response = request.GetResponse() as WebResponse; } catch (WebException ex) { response = ex.Response as WebResponse; } string result = string.Empty; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); }

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Moshiur Rahman June 29, 2014

Resolved the issue. NumberField has no quote; DatePickerField format should be "yyyy-mm-dd"

https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue#JIRARESTAPIExample-CreateIssue-Data

0 votes
Andy Nguyen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 28, 2014

Hi Moshiur,

If I'm not mistaken, you received an error with versions field not having Array values. Since this field is multi-value, you need to modify the syntax a little bit, adding Array[...] so that the JSON code will become:

{\"fields\":{\"project\":{\"id\":\"15320\"},\"issuetype\":{\"id\":\"25\"},\"summary\":\"Test\",\"description\":\"Test Desc\",\"priority\":{\"id\":\"2\"},\"versions\":[{\"id\":\"33157\"}]}}

Cheers.

Moshiur Rahman June 29, 2014

Hi Andy,

Thank you so much...that worked.

I have another set of fields for creating different issue and getting "400 bad request". Can anyone help me with this,

{"fields":{"project":{"key":"projectkey"},

"issuetype":{"id":"4"},

"summary":"Test summary",

"description":"Test Desc",

"priority":{"id":"2"},

"customfield_10211":{"id":"10554"},

"customfield_10213":"27/Jun/14",

"customfield_10212":"500.00",

"reporter":{"name":"username"},

"customfield_10224":"27/Jun/14",

"assignee":"name":"username"},

"customfield_10223":"600.00",

"customfield_10221":"tryerror",

"customfield_10220":{"id":"10703"},

"customfield_10219":"try creating issue",

"customfield_10482":{"id":"13456"},

"customfield_10481":{"id":"13452"},

"customfield_10484":"None",

"customfield_10483":{"id":"13457"},

"customfield_13182":"700.05",

"customfield_13184":{"name":"username"},

"customfield_13185":{"id":"23731"},

"customfield_13386":{"id":"23734"},

"customfield_13580":{"id":"23832"},

"customfield_13387":{"id":"23736"},

"customfield_13680":{"id":"24145"},

"customfield_13385":{"id":"23834"}}}

Thanks in advance

TAGS
AUG Leaders

Atlassian Community Events