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 edited
"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

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 Leaders.
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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
atlassian, out of office, loom, confluence, async collaboration, meeting recaps, remote teamwork, team alignment, knowledge sharing, AI-powered notes, productivity tools, workforce continuity, teamwork collection

Put your meeting notes on autopilot with Loom + Confluence

AI-powered meeting notes keep work moving even if you’re out of the office. Enjoy your well-deserved time off and return refreshed, confident you’ll catch up in no time.

Learn more
AUG Leaders

Atlassian Community Events