JIRA on creation of new issue

Joao Brandao October 31, 2017

Hey mates,

today i was trying to create a new issue using REST API from JIRA and I always get the error:

HTTP/1.1 405 Method Not Allowed 

I am using OAuth authentication to create and edit issues. I already edit a few fields on issues that are already created, but now I am trying to create new issue.

URL

 https://xpto.pt/rest/api/2/issue/

 

JSON code

{
"fields": {
"project": {
"key": "ProjectKey"
},
"component": "CAIX - TEST 1",
"summary": "TESTE REQ. NAME",
"issuetype": {
"name": "Issue"
},
"labels": ["CASE-TEST", "REQUIREMENT", "Tests"]
}
}

 Note: i change the project key and page of JIRA for this example.

My url: 

My JIRA version is V7.1.9.

I already search and find that is another way to create issues using rest/api/2/issue/createmeta, but i dont want to use that.

 

Do you have any ideia of whats is wrong ? If necessary i can put put a example of the code.

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2017

Hello,

REST API can send GET, POST, PUT, DELETE requests. Method Not Allowed usually means that you send a wrong request type. If you want to create an issue, it is a POST request. Make sure you make a POST request.

If the problem is not fixed kindly provide your code for making the request.

Joao Brandao October 31, 2017

I already try the json example from JIRA API but the error still appears. See the code i am using

{
    "fields": {
       "project":
       { 
          "key": "TEST"
       },
       "summary": "REST ye merry gentlemen.",
       "description": "Creating of an issue using project keys and issue type names using the REST API",
       "issuetype": {
          "name": "Bug"
       }
   }
}


 

I Post via this code:

uri is the page: https://xpto.jira.com/rest/api/2/issue/

json2 is the example

 

HttpPut put = new HttpPut(uri);
HttpResponse response = null;
put.setHeader("Content-Type", "application/json");
put.setHeader("Authorization", "Basic " + args.getJiraAuthToken());
try {
HttpEntity entity = new ByteArrayEntity(json2.getBytes("UTF-8"));
put.setEntity(entity);
response = httpClient.execute(put);

}catch (Exception e){
System.out.println(e);
}finally {
return response;
}

 

 

 

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2017

Replace new HttpPut(uri) with new HttpPost(uri)

Martin Varga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 31, 2017

What @Alexej_G said. Also:

rest/api/2/issue/createmeta

is not used to create issues. This is the meta data documentation for the fields you are sending to the create endpoint. 

Joao Brandao November 1, 2017

I already find the problem :)

Needed to change to HttpPost and need to change the IssueType.

 

@Martin Varga AND @Alexey Matveev Thanks for your help guys! If u need something from me, contact me :)

 

Suggest an answer

Log in or Sign up to answer