The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

How to fill custom field value while creating a issue through REST API

Anshul Mittal
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!
April 14, 2023
"customfield_123": {
"required": true,
"schema": {
"type": "option",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:select",
"customId": 123
},
"name": "Field_123",
"key": "customfield_123",
"hasDefaultValue": false,
"operations": [
"set"
],
"allowedValues": [
{
"self": "https://xyz.atlassian.net/rest/api/2/customFieldOption/1",
"value": "abc",
"id": "1"
},
{
"self": "https://xyz.atlassian.net/rest/api/2/customFieldOption/2",
"value": "pqr",
"id": "2"
}
]
}

I want to fill above field while creating issue using REST API in spring.

IssueInputBuilder issueBuilder = new IssueInputBuilder(projectKey, issueType, issueSummary);
issueBuilder.setFieldValue("customfield_123", 1L);

issueBuilder.setFieldValue("customfield_123", "1");

issueBuilder.setFieldValue("customfield_123", "abc");

I have used above variations and all giving the same error below.

Caused by: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={customfield_123=Specify a valid 'id' or 'name' for Field_123}, errorMessages=[]}]}


What should be approach here? 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Bill Sheboy
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 Champions.
April 15, 2023

Hi @Anshul Mittal -- Welcome to the Atlassian Community!

First thing, you might also want to look in the developer community for questions like this one: https://community.developer.atlassian.com/

Back to your question...and I have not tried this to verify...

That second parameter to setFieldValue() can be a ComplexIssueInputFieldValue, and so you would need to compose it as needed.  Your custom field appears to be a single select field and so you would need to provide either the id or name attribute for selection.

Kind regards,
Bill