Created
March 11, 2014 17:09
-
-
Save wizardishungry/9490340 to your computer and use it in GitHub Desktop.
scraped from https://answers.atlassian.com/questions/207169/create-issue-with-rest-api-and-curl-using-php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment