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.
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);
}
==================
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.