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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted 9 hours ago in Jira

Upcoming Enterprise releases targeting Q3 2019: Jira Software 8.5 & Jira Service Desk 4.5

Since launching the Jira Software 8.0 and Jira Service Desk 4.0 platform releases in February, many of you have been asking when the next Enterprise release will be so you can take advantage of the m...

182 views 0 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you