Forums

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

405 error when creating issue

Kamil-Szmit
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!
July 22, 2019
I try to create the issue in PHP (I cannot format this line as the nomal text):

$postvars = http_build_query(array('fields' => array('project' => array('key' => 'SUP'), 'summary' => $body, 'issuetype' => array("name" => "Bug"))));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://jira-address/rest/api/2/issue/createmeta');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, 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_USERPWD, 'login:password');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
$r = curl_exec($ch);
var_dump($body, $r, curl_error($ch));
die();

The above code returns:

string(4) "test" bool(false) string(38) "The requested URL returned error: 405 " 

Why JIra API returns HTTP error 405? How to resolve this problem? What is wrong with my code? How to create the issue in PHP? Can I check detailed information about the error? Could you help me?

1 answer

1 accepted

5 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 23, 2019

Hi Kamil,

Sorry to hear there is a 405 error here.  Typically these happen because there is a syntax problem in the way the request is being formatted.  The HTTP 405 is technically a METHOD not allowed error.   From looking at your call, it looks like you are trying use the HTTP POST verb on the endpoint /rest/api/2/issue/createmeta

However if we take a closer look at the Jira Server REST API docs on that endpoint you can see that this specific endpoint is only able to use the GET verb:  https://docs.atlassian.com/software/jira/docs/api/REST/8.3.0/#api/2/issue-getCreateIssueMeta

From that endpoint description:

Returns the meta data for creating issues. This includes the available projects, issue types and fields, including field types and whether or not those fields are required. Projects will not be returned if the user does not have permission to create issues in that project.

The fields in the createmeta correspond to the fields in the create screen for the project/issuetype. Fields not in the screen will not be in the createmeta.

So you might call that GET /rest/api/2/issue/createmeta to figure out what projects and field types are available to you before creating an issue, but this endpoint is not the correct on for actually creating new issues in Jira.   In this case, in order to create an issue you actually want to use a different endpoint, such as POST /rest/api/2/issue.

I'm no expert with PHP, but I think this could be as easy as changing your address from:

curl_setopt($ch, CURLOPT_URL, 'https://jira-address/rest/api/2/issue/createmeta');

into

curl_setopt($ch, CURLOPT_URL, 'https://jira-address/rest/api/2/issue');

Try this and let me know the results.

Cheers,

Andy

Suggest an answer

Log in or Sign up to answer