Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

JIRA API returns 405 errors. Works fine with curl

I am trying to make a simple Jira REST API call from my Eclipse  to Jira Cloud. This works fine with curl on same machine using the same URL and same credentials. 

 

curl -D- -X GET -H "Authorization:Basic bmF0aGFuQHMODIFIEDBYME==" -H "Content-type:application/json" "https://tracecloud.atlassian.net/rest/api/2/issue/PID-7"

 

Response : 


HTTP/1.1 200 OK
Server: AtlassianProxy/1.19.3.1
vary: Accept-Encoding

 

I am trying the same thing in my Java code : 

 

    

     try {

             // Create URL object

                   

            URL url = new URL("https://tracecloud.atlassian.net/rest/api/latest/issue/PID-7");

             conn = (HttpURLConnection) url.openConnection();

             conn.setDoOutput(true);

             conn.setRequestMethod("POST");

             conn.setRequestProperty("Content-Type", "application/json");

             

             conn.setRequestProperty("Authorization", "Basic bmF0aGFBase64JiraAPItoken==");

          

             os = conn.getOutputStream();

             os.write(input.getBytes());

             os.flush();

             

             System.out.println("response code is " + conn.getResponseCode());

             if(conn.getResponseCode() == 200){

                 br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

                 while((output = br.readLine()) != null){

                     loginResponse += output;

                 }

                 conn.disconnect();

             }

         } catch (Exception ex) {

             System.out.println("Error in loginToJira: " + ex.getMessage());

             loginResponse = "ERROR";

         }

     

     System.out.println("loginResponse  is " +loginResponse);

     

I did some research and tried the following :

 

1. Used HTTPS

2. This URL works fine, but returns HTML web page and not JSON.      // URL url = new URL( "https://tracecloud.atlassian.net/jira/software/projects/PID/boards/1?selectedIssue=PID-1");

3.  conn.setRequestProperty("dataType", "json");

 4. conn.setRequestProperty("cache-control", "no-cache");

  5.  conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");

 

I used to get 403 error, now I get 405 . Any help is much appreciated. 

 

          

1 answer

0 votes
Charlie Misonne Community Leader Dec 03, 2021

Hi Nathan,

In the java code you're performing a POST method, in curl you use a GET method.

That's most likely your issue.

Hi Charlie,

 

Thanks for the response. I had tried it with GET too. Same issue (405) error

 

             conn = (HttpURLConnection) url.openConnection();

             

             // Set properties

             conn.setDoOutput(true);

             conn.setRequestMethod("GET");

             conn.setRequestProperty("Content-Type", "application/json");

            // conn.setRequestProperty("dataType", "json");

             

             // this encoding is for nathan@tracecloud.com:JIRAAITOKEN

             conn.setRequestProperty("Authorization", "Basic bmF0aGFuQHRyYW

 

....

 

Nathan

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

253 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you