Forums

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

Jira REST API Update Summary of a ticket

Jacob Haskamp December 7, 2022

Hello, struggling to edit a ticket summary, I can already post comments with below: 

 

So I've been able to use python to sumbit a JSON POST command using the below code:

 

    def Send_Answer(comment, URL):

        request2 = session.post(URL, cookies=cookies, json = {
           
    "body": comment,
        })
        #soup = BeautifulSoup(response2.content, 'lxml')
        print("Request status code is ", request2.status_code)
           
    def Get_New_Link(ticket_url = 'Error, link required.'):
        response2 = session.get(ticket_url, cookies=cookies, allow_redirects=False)
        soup = BeautifulSoup(response2.content, 'lxml')
        index_code = soup.find_all('div', class_ = 'sd-comment-issue-page-edit-root')
        parse_text = index_code
        parse_text = str(parse_text)
        parse_text = parse_text.split(':')
        parse_text = parse_text[1]
        parse_text = re.sub('[^0-9]','', parse_text)
        custom_link = ('https://mycompanyurl/rest/api/2/issue/'+parse_text+'/comment')
        return custom_link

 

Despite my best efforts I can't update the summary. I've tried many combos including changing the link to and the JSON:

 

    def Send_Answer(comment, URL):
     
        request2 = session.post(URL, cookies=cookies, json = {
           
    "summary": "Testchange"
        })
        #soup = BeautifulSoup(response2.content, 'lxml')
        print("Request status code is ", request2.status_code)
       

    def Get_New_Link(ticket_url = 'Error, link required.'):
        response2 = session.get(ticket_url, cookies=cookies, allow_redirects=False)
        soup = BeautifulSoup(response2.content, 'lxml')
        index_code = soup.find_all('div', class_ = 'sd-comment-issue-page-edit-root')
        parse_text = index_code
        parse_text = str(parse_text)
        parse_text = parse_text.split(':')
        parse_text = parse_text[1]
        parse_text = re.sub('[^0-9]','', parse_text)
        custom_link = ('https://mycompaniesurl/rest/api/2/issue/'+parse_text+'?fields=summary')
        return custom_link

3 answers

1 accepted

3 votes
Answer accepted
Sunny Ape
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.
December 7, 2022

As per the Edit issue endpoint documentation, you don't update (change) an issue field with a POST request, but a PUT request.

Morgan DUBUISSON
Contributor
December 7, 2022

Well seen,

I had not paid attention to the method!
I don't know how to develop in python so I didn't look at the code.
I'm more on PowerShell or Node js.
I think your answer can fix the problem

Jacob Haskamp December 8, 2022

So simple ! That actually is likely the issue... I'm going to go down that rabbit hole using a PUT request instead of POST and see what I get. Thanks !

0 votes
Jacob Haskamp December 8, 2022

For anyone looking for a solution to this: 

 

Code: 

request2 = session.put(URL, cookies=cookies, json = {
           
            "fields": {"summary": "new summary"}
   
        })
Useful Link: 
Note:
Make sure to use the API Link without any additional text, just the /api/2/issue/issue_id
0 votes
Jacob Haskamp December 7, 2022

All of my attempts return a status code 405, so I know I'm close but lacking something I need. 

Morgan DUBUISSON
Contributor
December 7, 2022

Hi,
Do you have a preference in the choice of programming language?

I don't really understand this python script

Jacob Haskamp December 8, 2022

I prefer Python, this contains both. All this script is doing is sending a JSON Request to the REST API 

request2 = session.post(URLcookies=cookiesjson = {
           
    "summary""Testchange"
        })

So really I just need to figure out the right JSON code to send to the REST API to change a tickets summary

Suggest an answer

Log in or Sign up to answer