Create an Issue with third party field through rest api

G Ramachandra August 29, 2017

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
Steven F Behnke
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.
September 1, 2017

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

G Ramachandra September 1, 2017

Hi @Steven F 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; }
}

G Ramachandra September 1, 2017

And Response from JIRA server as below

JiraResponceFromServer.png

Steven F Behnke
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.
September 1, 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?

G Ramachandra September 1, 2017

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

Steven F Behnke
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.
September 1, 2017

You're not passing the right value.

G Ramachandra September 1, 2017

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

customfield_10300 = "TestTeam"

 

anything wrong here..

Steven F Behnke
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.
September 1, 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.

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 30, 2017

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events