I can successfully create an issue in jira using jira cloud rest api via my standalone python script below:
<span>from</span> jira <span>import</span> JIRA
<span>import</span> os
options = {<span>"server"</span>: <span>"https://mysite.atlassian.net"</span>}
username = os.environ.get(<span>"jira_username"</span>)
token = os.environ.get(<span>"api_token"</span>)
jira = JIRA(options, basic_auth=(username, token))
workRequest = {
<span>'project'</span> : {<span>'key'</span> : <span>'myprojectkey'</span>},
<span>'summary'</span> : <span>'Are you working?'</span>,
<span>'description'</span> : <span>'Testing, Testing'</span>,
<span>'issuetype'</span> : {<span>'name'</span> : <span>'Task'</span>}
}
new_issue = jira.create_issue(fields=workRequest)
print(new_issue)I am trying to build a basic flask webapp which consists of a generic webform that when submitted generates a jira ticket. The problem I am having is I am getting a 401 unauthorized error when I 'POST' from the form. I am confused as I am using the same code as above(See below for flask .py). I am new to the web development/python world and trying to get my feet wet. Any help would be greatly appreciated. (yes, I know there are issue collectors; I am trying to learn to create my own form webapp.)
<span>from</span> flask <span>import</span> Flask, render_template, request
<span>import</span> os
<span>from</span> jira <span>import</span> JIRA
app = Flask(__name__)
<span>def createRequest(testemail, freetext, jira):</span>
workRequest = {
<span>'project'</span>: {<span>'key'</span>: <span>'myprojectkey'</span>},
<span>'summary'</span>: <span>'Request from Flask Webform'</span>,
<span>'description'</span>: <span>'My email is: {} /nI would like {}'</span>.<span>format</span>(testemail, freetext),
<span>'issuetype'</span>: {<span>'name'</span>: <span>'Task'</span>}
}
new_issue = jira.create_issue(fields=workRequest)
<span>@app.route('/form', methods=["GET", "POST"])</span>
<span>def form():</span>
<span>if</span> request.method == <span>"POST"</span>:
testemail = request.form.get(<span>"testemail"</span>)
freetext = request.form.get(<span>"freetext"</span>)
options = {<span>"server"</span>: <span>"https://mysite.atlassian.net"</span>}
username = os.environ.get(<span>"jira_username"</span>)
token = os.environ.get(<span>"api_token"</span>)
jira = JIRA(options, basic_auth=(username, token)),
createRequest(testemail, freetext, jira)
<span>return</span> render_template(<span>"form.html"</span>)