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

Return HTTP code 404.

Hi,

 I am using Jira 7.13.0 and Jira base URL is

String urlCAL="http://192.168.1.236:8082/rest/attach-cat/2/attachments/get?issueKey="+issue;

and  

try
{
String authString = "vpsvalidator:8c5ydjGL0S8ZiZsODG2JetNqn";
String authStringEnc = Base64.getEncoder().encodeToString(authString.getBytes("utf-8"));
URL url = new URL(urlCAL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Authorization", "Basic " + authStringEnc);
if (conn.getResponseCode() != 200)
{
throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output = org.apache.commons.io.IOUtils.toString(br);
Pattern folderpattern = Pattern.compile("\"id\":(.+?),\"name\":\"(.+?)\",\"attachments\":(.+?)]") ;
Matcher foldermatch = folderpattern.matcher(output);
message1 = message1+ output;
while(foldermatch.find())
{
String attachmentsID = foldermatch.group(1);
String attachmentsFolders = foldermatch.group(2);
String attachmentsDetails = foldermatch.group(3);
if(attachmentsFolders.contains(requiredValue))
{
String folderFiles1 =attachmentsDetails.replace("{","");
String folderFiles2 =folderFiles1.replace("[","");
String folderFiles3 =folderFiles2.replaceAll("\"","");
folderFiles =folderFiles3.replace("ids:","");
message1= message1+folderFiles;
}
}
}
catch (Exception e)
{
e.printStackTrace();
throw new InvalidInputException(e+"Unable to Find the Selected folder"+message1+"---"+folderFiles+"==="+requiredValue);
}

 

then shows the HTTP error code: 404 not found.

1 answer

0 votes

Hi @shital chande ,

It can just be a copy-paste error, but from what I can see above you get error 404 because you are calling the endpoint below that does not exist:

String urlCAL="http://192.168.1.236:8082/rest/attach-cat/2/attachments/get?issueKey="+issue;

 

The correct endpoint to get all attachments for an issue is /rest/api/2/attachment/{id}. Therefore, your code would be instead something like:

String urlCAL="http://192.168.1.236:8082/rest/api/2/attachment/"+issue;

 

In other words, please notice that the base url is http://192.168.1.236:8082/ and the endpoints available to be called for Jira Server 7.13.x are the ones listed in the below documentation page:

 

Let me know if this helps.

 

Cheers,
Dario

Thank you, Dario, for replying me. and you provide a link is working

String urlCAL="http://192.168.1.236:8082/rest/api/2/attachment/"+issue;

but still, the same error has occurred. can you tell me please what can i change for following code to give me a list of attached files ?:

==========================

try
{
String authString = "vpsvalidator:8c5ydjGL0S8ZiZsODG2JetNqn";
String authStringEnc = Base64.getEncoder().encodeToString(authString.getBytes("utf-8"));
URL url = new URL(urlCAL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Authorization", "Basic " + authStringEnc);
if (conn.getResponseCode() != 200)
{
throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output = org.apache.commons.io.IOUtils.toString(br);
Pattern folderpattern = Pattern.compile("\"id\":(.+?),\"name\":\"(.+?)\",\"attachments\":(.+?)]") ;
Matcher foldermatch = folderpattern.matcher(output);
message1 = message1+ output;
while(foldermatch.find())
{
String attachmentsID = foldermatch.group(1);
String attachmentsFolders = foldermatch.group(2);
String attachmentsDetails = foldermatch.group(3);
if(attachmentsFolders.contains(requiredValue))
{
String folderFiles1 =attachmentsDetails.replace("{","");
String folderFiles2 =folderFiles1.replace("[","");
String folderFiles3 =folderFiles2.replaceAll("\"","");
folderFiles =folderFiles3.replace("ids:","");
message1= message1+folderFiles;
}
}
}
catch (Exception e)
{
e.printStackTrace();
throw new InvalidInputException(e+"Unable to Find the Selected folder"+message1+"---"+folderFiles+"==="+requiredValue);
}

==================

Dario B Atlassian Team Sep 09, 2019

Hi @shital chande , 

Do you get exactly the same error message or the error changed after changing the endpoint? Would you mind sharing the error message in here? (please make sure to remove the sensitive data, if any)

Also, kindly notice that I might not be the best person to help with the code and that for developers' related questions you might want to refer to the resources listed in https://developer.atlassian.com/resources:

 

Regards,
Dario

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,528 views 22 32
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