Hello,
I am trying to make an external web page that will also have a form. After completing the form I want the fields to be submitted and create a new Jira issue.
I wrote some php code and used the JIRA REST API but I can't figure out how to make it work. Anyone has a suggestion maybe? I mention I already tested the api using Advanced REST client (basically same tool as POSTMAN) and when I do it there it works, on my site it doesn't. Also "JIRA PLACEHOLDER" is replaced by the actual jira instance in my code. It is my first time trying to use API and I am a beginner with PHP. I will leave the code below.
Jira-create-issues.php :
<?php
$base64_usrpwd = base64_encode($_POST['user'].':'.$_POST['pass']); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://JIRA-PLACEHOLDER/jira/rest/api/2/issue/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$base64_usrpwd));
$arr['project'] = array( 'key' => 'TEST'); $arr['summary'] = $_POST['summary']; $arr['description'] = $_POST['description']; $arr['issuetype'] = array( 'name' => $_POST['type']); $json_arr['fields'] = $arr; $json_string = json_encode ($json_arr); curl_setopt($ch, CURLOPT_POSTFIELDS,$json_string); $result = curl_exec($ch); curl_close($ch); echo $result;
?>
And the code for jira-create-issue.html:
<html>
<head>
<script src="jquery-2.1.4.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="wrapper">
<h1>Create Issue</h1>
<form id="create-form"> Summary: <input type="text" name="summary" id="summary" value=""/> Description: <input type="text" name="description" id="description" value="" /> Issue Type: <input type="text" name="type" id="type" value=""/> Username: <input type="text" name="user" id="user" value=""/> Password: <input type="password" name="pass" id="pass" value=""/>
<input type="button" id="button" value="Create Issue"/>
</form>
</div>
<script>$('#button').click(function() { $.ajax({ type: "POST", url: "jira-create-issue.php", data: $('#create-form').serialize(), success: function(data){ alert(data);
}, dataType: "html"
});
});
</script>
</body>
</html>
You don't need to use the REST API to do this, you can use an Issue Collector in Jira, see here:
https://confluence.atlassian.com/adminjiracloud/using-the-issue-collector-776636529.html
Hey,
Thanks for the info.
I already know about the Issue Collector and tried to implement it. The problem is I am getting the following error:
You cannot create an issue collector for this project, because the following fields are required on the project and those field types cannot be displayed to anonymous users. If the field is changed to be optional or a default value is provided, then an issue collector can be created for the project. Not allowed fields: Assignee
This is a problem present since 2016 as I found out from https://jira.atlassian.com/browse/JRASERVER-63323
I am not able to "Allow unassigned issues", this is sadly not my decision so I am trying to work around it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah I see, sorry I wasn't aware of that issue.
I'm afraid I can't help with the PHP. But could you maybe try using the Issue Collector and specifying a default assignee, based on Component maybe?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We do have default assignee based on component. I will try this out and let you know. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've tried creating a custom collector that has a component field mandatory checked and I am still getting the same error mentioned above. I guess the collector is not a solution for our Jira instance sadly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.