Can't update custom field value via API

Mark Dodrill April 30, 2024

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.

1 answer

0 votes
David Bakkers
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 30, 2024

"I've tried to specify the data for the PATCH call"

You might want to try reading the documentation for the Edit Issue endpoint again. That endpoint uses a PUT method, not a PATCH method.

Suggest an answer

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

Atlassian Community Events