Forums

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

JIRA REST API returns HTTP error code : 404

shital chande August 22, 2019

Hi, I'm trying to use the JIRA rest API to get the issue is moved on one status to another, however, for all queries that I tried it returns 404 status.

An example http://localhost:8080/rest/attach-cat/1.0/attachments/get?issueKey=" +issue, however, it returns 404.

And Jira is 7.13.0

1 answer

1 accepted

0 votes
Answer accepted
Tomas Gustavsson
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.
August 22, 2019

URI structure

http://host:port/context/rest/api-name/api-version/resource-name
https://jira.atlassian.com/rest/api/latest/issue/JRA-9

 

Please check
https://developer.atlassian.com/server/jira/platform/rest-apis/

shital chande August 22, 2019

Hi Tomas Gustavsson,

  Actually, I am using Smart attachment plugin 2.3.0 version and I am updating Meta Validation Plugin and that using URI http://localhost:8080/rest/attach-cat/1.0/attachments/get?issueKey=" +issue  for getting the issue id's, however, it returns HTTP Failed Error Code is 404. then how to solve this error?

Like sara hanfi likes this
shital chande September 7, 2019

Thank you,

Tomas Gustavsson,

, for replying me. and now following 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);
}

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

Tomas Gustavsson
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.
September 9, 2019

To get the Attachments, you need to have the attachments id. ex like below. 
https://jira/rest/api/2/attachment/139053

 

so first you need to find the issue and see if i holds any attachments, and then get the attachments Id, then you can use that to request it.

some more info here
https://community.atlassian.com/t5/Jira-questions/How-to-retrieve-an-issue-attachments-with-the-rest-api/qaq-p/572084

shital chande September 9, 2019

Thanks, Tomas for understanding my concept and I want to use the GET method to find the issue and see if I hold any attachments, and then get the attachments Id then what I need to do change the below code : 

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());
}
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
message1 = message1+ org.apache.commons.io.IOUtils.toString(br);
folderpattern = Pattern.compile("\"id\":(.+?),\"name\":\"(.+?)\",\"attachments\":(.+?)]");
Matcher foldermatch = folderpattern.matcher(message1);
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");
}

 

can you suggest to me?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events