It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unable to edit an Issue through Jira Rest API

I am trying to edit a JIRA Issue using REST API . I get a 405 error when I run the following code.

I already read https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-edit-issues . But I don't understand why I am getting a 405.

I also checked https://**.atlassian.net/rest/api/latest/issue/TI-81/editmeta/ , which gives the list of fields I can edit.

newValues = dumps(
{
"update": {
"summary": [
{
"set": "blah "
}
]
}
})
newValues = dumps({
"fields":
{
"summary":"CLONE - Testing label stuff",
"assignee":{"name":"admin"}
}
})
headers = {"Authorization": " Basic " + b64encode(username + ":" + password), "Content-Type": "application/json"}
try:
request = requests.put("https://****.atlassian.net/rest/api/latest/issue/"+IssueID+"/editmeta", data=newValues, headers=headers)
print request
except urllib2.HTTPError, error:
print error.read()

 

Can someone help me with the issue or provide a working python code to edit issue by key/ID??

 

3 answers

1 vote

Hello Jag,

Thank you for your question.

Please, run the following:

import requests, json, base64

username = 'YOUR_USERNAME'
password = 'YOUR_PASSWORD'

pageData = {
    "fields":
    {
        "summary":"NEW SUMMARY",
        "assignee":{"name":"USERNAME"},
        "priority":{"id":"INTEGER"},
    }
}
headers = {
    "Authorization": " Basic " + base64.b64encode(username + ":" + password), 
    "Content-Type": "application/json"
}
    
print json.dumps(pageData)    
    
r = requests.put(
    'https://DOMAIN.atlassian.net/rest/api/2/issue/ISSUE-KEY',
    data=json.dumps(pageData),
    headers=(headers)
)
    
print r

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

Kind regards,
Rafael P. Sperafico
Atlassian Support

fields might got added to screens more than once.

To identify duplicate entries use this query

select f.name, i.fieldidentifier, count(*)
from fieldscreen f, fieldscreenlayoutitem i, fieldscreentab t
where f.id = t.fieldscreen
and i.fieldscreentab = t.id
group by f.name, i.fieldidentifier having count(*) > 1;

 

Based on the results, remove those fields from respective screens.

 

Thank You

Madhu

Hi Jag,

The error 405 "Method not allowed" happens because urllib2 does POST instead of PUT. I also had this one.

The next code works for me:


    opener = urllib2.build_opener(urllib2.HTTPHandler)
    queryURL = serverURL + '/rest/api/latest/issue/' + taskID

    newValue = {
        "fields": {
            "customfield_10500": new_value
        }
    }

    req = urllib2.Request(queryURL)
    req.add_data(json.dumps(newValue))
    req.add_header("Content-type", "application/json")
    req.add_header("Accept", "application/json")
    req.get_method = lambda: 'PUT' # this line is the key!
    fp = opener.open(req)
    fp.close()

Best regards,

Eugene

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in United States

Live! - Austin ACE -- Summer BASH 2019

Hey Austin! Come join us for our 2019 Atlassian Community Summer BASH as we transition ourselves into party status! Bring an attachment, log a great time, and collaborate with new friends as we celeb...

13 views 0 0
View post

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you