Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira create issue with php curl api

S
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 29, 2018

Hii,

 

When i am creating jira issue with php curl, getting error "bad request". I dono what happended with my code .Can anybody solve this issue.?

below attached my code :

$username = "xxxx"; //this dummy username and password
$password = "xxxxx";

$url="https://emantrasjira.gpstrategies.com/jira/rest/api/2/issue/";
            
      $data = array(
       "fields" => array(
        "project" => array("key" => "JTP"),
        "summary" => "Weekly cleaning up of the engineering lab",
        "description" => "Description of issue goes here.",        
        "issuetype" => array("name" => "Bug")        
       )
      );
 
            
      $ch = curl_init();
      
      $headers = array(
      
       "Accept: application/json",
      
       "Content-Type: application/json"
      
      );
      
              
         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");
      
       //print_r(curl_getinfo($ch)) ;
      
      $result = curl_exec($ch);
      
      $ch_error = curl_error($ch);
      
      
      
      if ($ch_error) {
      
       echo "cURL Error: $ch_error";
       
      
      } else {
      
       echo $result;
          
      }
      
       
      
      curl_close($ch);   

 

1 answer

0 votes
Alex Koxaras -Relational-
Community Champion
August 13, 2021

Hi @S 

Did you take a look at the latest API documentation and cross check what you've written?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events