Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to update customfield using python, however it work well using curl

RAlam September 15, 2022

Hi there,

I'm trying to update a custom field "customfield_16220" using python which is failing. It errors 400.

However, the curl works fine.

curl request:

curl --request PUT \
--url 'https://jira.xxxxx.com/rest/api/2/issue/cdc2-96' \
--header 'Authorization: Bearer <token>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"fields": {"customfield_16220":[{"name": "r.a@dddd.com"}]}}

 python code:

 

import requests
import json

cf='customfield_16220'
access_token="<token>"

url = "https://jira.xxxxx.com/rest/api/2/issue/cdc2-96"
payload = {"fields": {"customfield_16220":[{"name": "r.a@dddd.com"}]}}

headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token
}

response = requests.request('PUT',url, headers=headers, data=payload, verify=False)
print(response)


It returns error code 400. Error: 

{"errorMessages": ["Unrecognized token 'fields': was expecting 'null', 'true', 'false' or NaN\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4bc1dc14; line: 1, column: 8]"]}

 

Here I must tell you that the same python code with the "GET" request (without data) is working fine and that is returning the issue details.


Can you please help me here in updating the customfield?

1 answer

1 accepted

0 votes
Answer accepted
Prince Nyeche
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.
September 15, 2022

Try using

response = requests.request('PUT',url, headers=headers, json=payload, verify=False)

The difference is, when using the json argument, you're sending a JSON serializable python object instead. 

RAlam September 15, 2022

Thank you @Prince Nyeche . It resolved my issue.

Suggest an answer

Log in or Sign up to answer