Forums

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

Create Jira issue using API, C#, JSON & HttpWebRequest

David Wells January 19, 2019

I have previously developed code to create an issue to Jira using API.

It was developed using Jira API, C#, JSON and HttpWebRequest. 

A new requirement to include 2 custom fields has caused this question. The fields are both of type Text Field (single line).  When I include the custom fields in my JSON data line, I get "The remote server returned an error: (400) Bad Request." error from the server. 

My assumption is that my logic using HttpWebRequest in C# is sound, because I can create an issue without including the custom fields without error. 

Please review the below JSON data line and tell me what I have done wrong, or whether this can be done using Jira API.

 

{
"fields":
{
"project":
{
"key":"TP"
},
"summary":"Test using custom fields",
"description":"Test creating issue with 2 custom fields.",
"issuetype":
{
"name":"Task"
},
"customfield_10901": "Test 2",
"customfield_10902": "Test 1"
}
}

 

Thank you.

3 answers

1 accepted

0 votes
Answer accepted
David Wells January 21, 2019

I found a work around by using update instead of create. Once a issue is created I then update custom fields. This works.

This allows me to move forward, but if anyone can help me with creating a new issue with custom fields, I would be interested in understanding what I have missed.

 

Thank you.

0 votes
Israel Maldonado
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 29, 2019

Not exactly in C# but I usually first create a bash file named bashInsert.bat to call my json script, the content of the .bat file is something like this:

curl -D- -u user:password -X POST --data @/Users/MyUser/Documents/testInsert.json -H "Content-Type: application/json" https://jira.domain.com/rest/api/2/issue/

 

-------------------------------------------------------------

Then the my testInsert.json that I will be calling seems like the following:


{
"fields": {
"project":
{
"key": "MXS000000"
},
"summary": "As user I would like to test the OK button",
"description": "Test the OK but and see what happens",
"issuetype": {
"name": "Test"
}
}
}

I reviewed what you have written and seems to be right, I just be checking about the permissions on your customfields?

0 votes
Edwin Kyalangalilwa
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.
January 20, 2019

Hi @David Wells,

Please confirm these two fields are on the create screen.

David Wells January 20, 2019

Both are on the create screen. 

I have also tried to update an existing issue with these fields and get the same error.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events