Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,369,740
Community Members
 
Community Events
168
Community Groups

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

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

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. 

Thank you @Prince Nyeche . It resolved my issue.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events