Hi
Could pls someone post an example code, how to create an issue with the rest api? i dont get it.
i am always getting a php error 415.
I think i am doing smth wrong^^
this would be my code so far:
<?php
$handle=curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Basic YWRtaW46eWFoYWxh'
);
$data = <<<JSON
{
"fields": {
"project":
{
"key": "SYNC"
},
"summary": "No REST for the Wicked.",
"description": "Creating of an issue using ids for projects and issue types using the REST API",
}
}
JSON;
curl_setopt_array(
$handle,
array(
CURLOPT_URL=>'baseurl/jira/rest/api/2/issue/',
CURLOPT_POST=>true,
//CURLOPT_HTTPGET =>true,
CURLOPT_VERBOSE=>1,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_RETURNTRANSFER=>true,
CURL_HEADER=>false,
CURLOPT_HTTPHEADER=> $headers,
CURLOPT_USERPWD=>"user:pwd",
//CURLOPT_CUSTOMREQUEST=>"POST"
)
);
$result=curl_exec($handle);
$ch_error = curl_error($handle);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
echo $result;
}
curl_close($handle);
?>
i hope someone can help me ;)
kind regards
chris
Community moderators have prevented the ability to post new answers.
it works fine! Thank you man!
her is now my code, if someone else would like to create issues ;)
<?php $username = 'xxxxx'; $password = 'xxxxx'; $url = "xxxx/rest/api/2/issue/"; $data = array( 'fields' => array( 'project' => array( 'key' => 'xxx', ), 'summary' => 'This is summary', 'description' => 'This is description', "issuetype" => array( "self" => "xxxx", "id" => "xxxx", "description" => "xxxxx", "iconUrl" => "xxxxx", "name" => "xxxx", "subtask" => false ), ), ); $ch = curl_init(); $headers = array( 'Accept: application/json', 'Content-Type: application/json' ); $test = "This is the content of the custom field."; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); $result = curl_exec($ch); $ch_error = curl_error($ch); if ($ch_error) { echo "cURL Error: $ch_error"; } else { echo $result; } curl_close($ch); ?>
No worries mate, please accept your answer so it can benefit others :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have created this PHP code somewhile ago to fetch some projects from JIRA, you may change the URL and the request type to add new issues :
<?php $username = 'test'; $password = 'test'; $url = "https://xxxxx.xxxxxxx.net/rest/api/2/project"; $ch = curl_init(); $headers = array( 'Accept: application/json', 'Content-Type: application/json' ); $test = "This is the content of the custom field."; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); //curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); $result = curl_exec($ch); $ch_error = curl_error($ch); if ($ch_error) { echo "cURL Error: $ch_error"; } else { echo $result; } curl_close($ch); ?>
So if you want to re-use it for creating issues, you will need to change the REST URL to /rest/api/2/issue/ and use "POST" instead of "GET"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Christoph! I am facing the same problem, i always receive an 415 error, what did you do to solve that problem? Could you help me out? Best regards!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
when i am using this code for example i am getting this error :
{"errorMessages":["Invalid numeric value: Missing integer part (next char '-' (code 45))\n at [Source: org.apache.catalina.connector.CoyoteInputStream@61c72476; line: 1, column: 3]"]}
<?php $data = array( 'fields' => array( 'project' => array( 'key' => 'TEST', ), 'summary' => 'This is summary', 'description' => 'This is description', ), ); $username = '***'; $password = '***'; $url = '***rest/api/2/issue/'; $curl = curl_init(); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $issue_list = (curl_exec($curl)); echo hi . $issue_list; ?>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
unfortunately it has not solved my problem...
it would be greate, if someone has an example how to create an issue with php using curl
i tried some different examples, which i found on the internet but none of them worked correctly :/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not good with php, but found this post in stackoverflow which similar to the way of your codings: http://stackoverflow.com/a/11091261
You might want to try the way you specified the headers and see how it goes?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.