Create an Issue with third party field through rest api Edited

Hi Team,

while creating the issue through REST API, 'Team' field of JIRA Portfolio is not populating.

I am trying to update Team with Custom ID: customfield_10300.

your immediate help is highly appreciated

 

Thanks and Regards

Ramachandra Reddy

2 answers

0 votes

JIRA won't let you create a new field during an issue creation/update.  Those fields have to exist in JIRA already before you can update a value for that field on that issue.

 

There is a way to create new custom fields via REST as per https://docs.atlassian.com/jira/REST/server/#api/2/field

Alternatively you can also create the custom field with that name in the JIRA GUI as explained in Adding a Custom Field.   Please note that when you first create a custom field in JIRA, you will probably have to reindex JIRA in order to then be able to use that new custom field.

0 votes
Steven Behnke Community Champion Sep 01, 2017

@G Ramachandra, can you show us the code you're using and the response from the server?

Hi @Steven Behnke,

please find my code as below.

RestClient client = new RestClient("https://myproject.atlassian.net/rest/api/2");
RestRequest request = new RestRequest("issue/", Method.POST);

client.Authenticator = new HttpBasicAuthenticator(txtJIRAUN.Text, txtJIRAUP.Text);

createIssue(request, client);


private void createIssue(RestRequest request, RestClient client)
{
try
{
var issue = new Issue
{
fields =
new Fields
{
description = JiraDesc,
summary = _tfsTitle,
project = new Project { key = "ProjectName" },
issuetype = new IssueType { name = "IssueType" },
priority = new Priority { name = _priority },
customfield_10400 = _tfsID,
customfield_11201 = _custName,
customfield_11500 = _supportid,
customfield_11100 = new Customfield_11100 { value = _itemType },
customfield_10300 = "TestTeam",
}
};


request.RequestFormat = DataFormat.Json;
request.AddJsonBody(issue);

var res = client.Execute<Issue>(request);
if (res.StatusDescription == "Created")
{
_jiraKey = res.Data.key;
bg.ReportProgress(0, "Issue Created, Id: " + _jiraKey);
}
else
{
bg.ReportProgress(0, "Issue Not Created.");
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

 

public class Issue
{
public string id { get; set; }
public string key { get; set; }
public Fields fields { get; set; }
}

public class Fields
{
public Project project { get; set; }
public IssueType issuetype { get; set; }
public Priority priority { get; set; }
public string summary { get; set; }
public string description { get; set; }
public string customfield_10400 { get; set; }
public string customfield_11500 { get; set; }
public string customfield_11201 { get; set; }
public Customfield_11100 customfield_11100 { get; set; }
public string customfield_10300 { get; set; }

}

public class Project
{
public string id { get; set; }
public string key { get; set; }
}
public class IssueType
{
public string id { get; set; }
public string name { get; set; }
}

public class Priority
{
public string id { get; set; }
public string name { get; set; }
}
public class Customfield_11100
{
public string id { get; set; }
public string value { get; set; }
}

And Response from JIRA server as below

JiraResponceFromServer.png

Steven Behnke Community Champion Sep 01, 2017

Okay, the error clearly states the problem. 

Team with ID 'TestTeam' could not be found

Can you create an issue in JIRA with the Team field set to TestTeam and perform an HTTP GET on /rest/api/2/issue/issueKey so you know what you need to send to JIRA?

TestTeam is available in Team field in JIRA. I can select Team field as TestTeam in JIRA, It's working fine.

Steven Behnke Community Champion Sep 01, 2017

You're not passing the right value.

I am passing TestTeam as below. (as mention in my code)

customfield_10300 = "TestTeam"

 

anything wrong here..

Steven Behnke Community Champion Sep 01, 2017

Can you perform an HTTP GET on an issue with it so you can see what value is stored? If the API isn't documented you should at least take a look at the GET shape and we can hope it's the same shape to POST/PUT.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

20,479 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you