Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

How to use a web form to create a Jira Edited

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> 

 

1 answer

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.

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?

 We do have default assignee  based on component. I will try this out and let you know. Thanks.

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. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

335 views 23 8
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you