Jira API and SelectList with REST

I'm trying to create an issue with custom fields. I have a custom field that is a selectlist. I pass in the following JSON:

{
"fields": {
"project": {
"key": "KEY"
},
"summary": "This is a test from the jira api",
"description": "Some description",
"issuetype": {
"id": "1"
},
"customfield_1": [
{
"id": "1234"
}
],
"customfield_2": [ // THIS IS THE SELECTLIST
{
"name": "1234"
}
]
}
}

I get back: Could not find valid 'id' or 'value' in the Parent Option object.

I've tried several different variations, none of which have worked. What is the correct way of sending a value for a custom selectlist?

4 answers

I think it might actually be easier, if you could post the result of

http://localhost:8090/rest/api/2/issue/createmeta?projectKeys=KEY&issuetypeIds=1&expand=project.issuetypes.fields

I can actually use

"customfield_10000":[{"value":"First Value"},{"value":"Second Value"}]

and

"customfield_10200":{"value":"Four"}

customfield_10000 is a of the type "Multi Select" and customfield_10200 is of the type "Select List" .

(And I can use "id" as well)

What grates on my nerves is that with the "built in" field types the key is "name" and with the custom fields it's "value" .

According to the tutorial https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue you should use "value" instead of "name" if customfield_2 is a multiselect custom field.

please also note that you have to use "name" if the field is a single select custom field and no [ ... ] brackets.

EDIT: The tutorial is not correct regarding the example for select lists. If you want to provide the custom field option value by name one has to use the attribute "value", not "name". At least this is the behaviour i have observed in 5.1m2

I tried that and I get the same error. Here is the JSON as it looks now:

{
"fields": {
"project": {
"key": "KEY"
},
"summary": "This is a test from the jira api",
"description": "Some description",
"issuetype": {
"id": "1"
},
"customfield_1": [
{
"id": "1234"
}
],
"customfield_2": { // THIS IS THE SELECTLIST
"name": "1234"
}
}
}

What i don't understand in your example is the id of your custom fields. Custom fields can't have and id of 1 or 2 or is this just to make the example more readable? What are the exact types of your custom fields when you display them in Administration - Issues - Fields ?

It's just to add clarity, not to confuse. The exact types of the custom fields that are in question are commented in the example. The one giving me issues is a select list, or drop down list if you prefer.

I have now verified it in my own test project what really works. Please note this:

1. You always need to use "value", not "name" (for multiselect and select fields). The documentation in the tutorial is not correct.

2. If you use comments in the request this confuses the parser. Don't use comments in the JSON post data

I've got the following working:

{
  "fields": {
    "project": {
      "key": "TESTDIETER"
    },
    "summary": "This is a test from the jira api",
    "description": "Some description",
    "issuetype": {
      "id": "1"
    },
    "customfield_10000": [ {  "value": "Cosy" }, {"value":"Loud"} ], 
    "customfield_10100": {  "value": "Brasil" } 
  }
}

customfield_10000 is a multiselect field, customfield_10100 is a select list field. This works on 5.1m2 (not tested yet with 5.0.3)

Here is my new JSON. Also note, the comments were only here in the post. I have no comments in the code.

{
"fields": {
"project": {
"key": "TEST"
},
"summary": "This is a test from the jira api",
"description": "Some description",
"issuetype": {
"id": "1"
},
"customfield_10000": [
{
"value": "1234"
}
],
"customfield_10100": {
"value": "1234"
}
}
}

Now it tells me

{"errorMessages":[],"errors":{"customfield_10000":"Option value '1234' is not valid","customfield_10100":"Option id 'null' is not valid"}}

1234 in this example is a valid value for both fields. That has been verified.

I assume you have replaced 10000 and 10100 by the id's of your custom field ...

That was just for the example.

The only thing i can imagine with the first custom field option 1234 is that it might contain a leading or trailing blank when you added the option. Are you sure the second custom field is really a multi select field and not a cascading select field? The values for these two types of fields must be specified differently in the JSON request (check the tutorial)

When you create the issue manually, can you select the options 1234 bor both fields? If not it might be because the options are not configured in the project specific configuration context of the custom field. In that case of course the JSON request will also fail.

If all the previous fails, you should get information about the valid date on create. Please use this request and post the result so we can check what the valid input is:

http://localhost:8090/rest/api/2/issue/createmeta?projectKeys=TEST&expand=project.issuetypes.fields

The field in question is not a multiselect. it is just a regular select. i have checked the tutorial, which is why I am here.

I have almost the same issue.

image2016-9-21 13:38:15.png

Now, when I try to create a bug using cURl, I get error message as

image2016-9-21 13:36:24.png

My jason script is

image2016-9-21 13:39:44.png

But if i do "ID" instead of value im good. its working fine. My requirement is that I should not use ID because if I use ID it will always create a bug only with that ID. So how would i be able to use value instead of ID. Please advice.

 

I had the original problem with a regular select. It takes an "id" field, not "name" or "value".

Hi, i have custom multiselect field, this my POST:

{

"update": {

"comment": [

{

"add": {

"body": "Bug has been fixed."

}

}

]

},

"transition":

{

"id": "42"

},

"fields":

{

"customfield_10313": [{ "value": "10360" }]

}

}

But i have 400 error.If i POST

{

"update": {

"comment": [

{

"add": {

"body": "Bug has been fixed."

}

}

]

},

"transition":

{

"id": "42"

}

}

Without fields, i have 204 but noting happen, i think this custom field is required. What is wrong?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

134 views 0 3
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