Adding value to dropdown via REST API python

Arjay Villavicencio October 21, 2021

I'm trying to add a non existent value to a drop down with empty list. Please check my code below and please let me know what is lacking.

I am following this documentation but I couldn't get it working.

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-rest-api-3-field-fieldid-context-contextid-option-post


def add_value():

url = "https://company.atlassian.net/rest/api/3/field/customfield_10000/option"

auth = HTTPBasicAuth(user, token)

headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

payload = json.dumps( {
"options": [
{
"disabled": "false",
"value": "Scranton"
},
{
"disabled": "true",
"value": "Manhattan"
},
{
"disabled": "false",
"value": "The Electric City"
}
]
})

response = requests.request(
"POST",
url,
headers=headers,
auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

 

=====

 

Error:


{
"errorMessages": [
"No content to map to Object due to end of input"
]
}

2 answers

1 accepted

0 votes
Answer accepted
Arjay Villavicencio October 21, 2021

Yeah! Context/contextid is the key!

0 votes
Arjay Villavicencio October 21, 2021

Updated code.

Made changes on the response variable,

response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)

It's still not working:

 

Error:

{
"errorMessages": [],
"errors": {
"value": "value is required"
}
}

 

Is the context/{contextID} required?

url = "https://your-domain.atlassian.net/rest/api/3/field/{fieldId}/context/{contextId}/option"

 

How am I going to identify or where am I going to get the context id?

S October 28, 2022

what was the context id?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events