How can I add options to a Select List custom field via Rest Api?

Hey. I am trying to update my customfield, selected list. I have already inquired on this site https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get , but it did not work or it could also be that I have implented it wrong. Can someone give an exact example how it has to work ?

1 Like

@DamlaNazYilmaz welcome to the Atlassian developer community.

The custom field types are tricky. There’s a great reference on our support site about Advanced field editing with detailed examples for pretty much anything you need to set. For the case of single-select list:

"customfield_11449" : { "value": "option3" }

or

"customfield_11449" : { "id": 10112 }

And just for the sake of having a complete JSON request body, here’s an example that works on my site:

{
    "fields": {
        "project": { "key": "TIS" },
        "issuetype": { "id": "10000" },
        "customfield_10432" : { "value": "Positive" },
        "summary": "Main order flow broken",
        "description": {
            "type": "doc",
            "version": 1,
            "content": [
                {
                    "type": "paragraph",
                    "content": [
                        {
                            "type": "inlineCard",
                            "attrs": {
                                "url": "https://devpartisan.atlassian.net/browse/NGEW-1"
                            }
                        }
                    ]
                }
            ]
        }
    }
}

Pay particular attention to the id example where there are no quotes. There are some fields that require quotes for id. Also, some fields require the use of operations inside the payload, like update and add.

2 Likes

Hey and thank you for the kind answer but I think I expressed myself a little wrong. I wanted to add an additional option which does not exist before. So let’s assume that I have already set option 1 and option 2 manually before. But now I also want to create option 3 but through rest api.

1 Like

I see. As you already may have guessed, that’s a different part of the API and can’t be done while creating an issue. It requires a different set of permissions. And this part is undergoing a bit of recent change. As such, you’ll find both deprecated endpoints and new experimental ones.

In your case, I recommend Update custom field options (context) using PUT /rest/api/3/field/{fieldId}/context/{contextId}/option. If you have any problems applying that new documentation, please let us know; it’s a great opportunity for us to make it better for everyone.

2 Likes

Thank you^^

Hi @ibuchanan

I am trying to list values inside the custom field (single select) using the API below is the behavior I created but it’s not working:

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

import groovy.json.JsonBuilder
import groovy.json.StreamingJsonBuilder;
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper

@BaseScript FieldBehaviours fieldBehaviours

def serviceProvider= getFieldByName(“Service Provider”).getValue()

def supplierAPI = new JsonSlurper().parse(new URL(“http://perfect-day-demo.herokuapp.com/api/meta/logistics_suppliers”))
def searchsupplier = supplierAPI.findAll{it.name=="${serviceProvider}"}

String SP =searchsupplier[0].name

Can you please help me for correcting the code

@AshishBijlwan welcome to the Atlassian developer community.

I recommend creating a new topic for your question. The original question was already marked as solved. Also, your question is really on a different topic because it isn’t using the Jira REST APIs, but external REST APIs. For some other tips, consider How To Ask A Good Question ❓

1 Like

Hi @ibuchanan
I have create a new topic as you suggested. List values inside the custom field (single select) using the External API
Please have a look into that.

Thanks,
Ashish