Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72443

PHP Form to create a Jira issue is not working

$
0
0

I am a beginner regarding working with php and api. What I am trying to do is create a new Jira issue using the Jira Rest Api. It is my first project of this type. I will post bellow the code from my 2 pages. I can't figure out what is my problem. 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. I mention that "JIRA PLACEHOLDER" is replaced by the actual jira instance in my code.

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> 

Viewing all articles
Browse latest Browse all 72443

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>