I have been trying to update a custom field's value in a Jira Cloud instance via the API, and every time I get a 400 error. I believe the problem is in how I specify the body of the data to update. I've done many searches, looked at API docs, and tried to find other examples, but no luck. I have verified I'm using the correct URL with the correct auth token and have the correct permissions in Jira.
Code is below. The custom field I'm trying to apply a new value to is a single line text field. Commented code are all the other ways I've tried to specify the data for the PATCH call, but in all cases they return a 400. I would appreciate some help since it seems like there is some small thing wrong, but I don't know what it is.
import requests
from requests.auth import HTTPBasicAuth
import json
url = f"{JIRA_DEST_URL}/rest/api/3/issue/{issue_key}"
header = {
"Accept": "application/json",
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true"
}
custom_field_id2 = "customfield_10083"
customfield_value = "Foo"
#custom_field_preparation = {custom_field_id2: customfield_value}
#custom_field_preparation = { "update": { custom_field_id2: [ {"set": customfield_value}]}}
#custom_field_preparation = [{"fields": [{custom_field_id2: { "value": customfield_value}}]}]
#custom_field_preparation = [{'fields': [{custom_field_id2: { 'value': customfield_value}}]}]
custom_field_preparation = {
"fields": {
custom_field_id2: customfield_value
}
}
response = requests.patch(url,
json=custom_field_preparation,
headers=header,
auth=HTTPBasicAuth(SOURCE_EMAIL, SOURCE_API_TOKEN))
Thanks for the help.