POST request to import workflow XML

Jose Partida Huerta January 26, 2023

Hi,

I'm a Jira admin and I'm trying to develop a python script to import XML workflows through the workflow XML definition option from:

<Base URL>secure/admin/workflows/ImportWorkflowFromXml!default.jspa

I'm using the "request" module to do a POST call and send the data to the form in above URL but, the only thing that the POST call it's doing it's to fill the form without  submitting it.

I have checked the chrome dev tools to monitor the POST call from the browser to mimic and send the same payload, headers, URL, etc. But without success.

I'm using PyCharm and Postman to test the POST requests and in both tools I'm getting 200 response code while in the browser I get a 302 response code, which is normal because it redirects the request to "/secure/admin/workflows/ListWorkflows.jspa" once the form is submitted, but I can't get the same behavior from PyCharm or Postman.


Python Script


import requests
import json

url = 'https://<Base URL>/secure/admin/workflows/ImportWorkflowFromXml!default.jspa'
headers = {
"Authorization": "<Personal Access Token>"
}
form_data = {
"name": "testing",
"description": "",
"definition": "inline",
"filePath": "",
"workflowXML": '<XML Workflow Definition>',
"Import": "Import"
}

with requests.session() as s:

s.get(url, headers=headers) #//Getting the cookies and Session ID

headers['Cookie'] = '; '.join([x.name + '=' + x.value for x in s.cookies])
headers['Content-Type'] = 'application/x-www-form-urlencoded'
headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
headers['Accept-Encoding'] = 'gzip, deflate, br'
s.headers.update(headers)

post_response = s.post(
url,
form_data,
cookies=s.cookies
)

print
(post_response.text)
print(post_response.status_code)

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events