Itai Malek
Itai Malek

Reputation: 301

using CURL in PHP to add an issue in JIRA via REST API

I'm trying to build an app that will write an issue to JIRA using REST API, I tried to implement it in PHP using CURL but i get an error telling me "The specified HTTP method is not allowed for the requested resource (Method Not Allowed)." can you take a look and tell me what am i doing wrong?:

 <?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",
       "issuetype": {
          "name": "Bug"
       }
   }
}
JSON;



curl_setopt_array(
$handle,
array(
CURLOPT_URL=>'http://localhost:8084/rest/api/2/issue/',
CURL_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=>"admin:yahala"
//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);




?>

Upvotes: 3

Views: 3993

Answers (1)

nairbv
nairbv

Reputation: 4323

I think it's CURLOPT_POST, not CURL_POST. Since CURLOPT_POST didn't correctly get set, it will probably default to GET which isn't allowed for that method.

Upvotes: 1

Related Questions