Forums

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

How to use JIRA REST API to fetch the issues in Json from the JIRA?

manoj singh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 31, 2017

This question is in reference to Atlassian Documentation: How to export JIRA application issues to JSON

I am very new to JIRA and REST. I googled it and learned few things. In most of the code snippet I saw it uses the localhost URL to get an issue, how do API JIRA response from localhost ?.
Also in some example I saw the URL like (https://jira.atlassian.com/rest/api/latest/issue/JRA-9.json) on this I can see JSON response to it but when I am trying access my issues with the same URL I don't see JSON response for it. eg: my issue URL is (http://jira-wifi.lmera.ericsson.se/browse/BN-1xxxx) on this I can my issues on GUI but when accessing API URL (https://jira.atlassian.com/rest/api/latest/issue/BN-1xxxx.json) I get a response 

{"errorMessages":["Issue Does Not Exist"],"errors":{}}.

 

Can someone please help on this ? 

1 answer

1 vote
Nic Brough -Adaptavist-
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.
January 31, 2017

The example you've found looks wrong to me.

Try the same url, but with no .json on the end.

manoj singh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 2, 2017

Hi Nic,

The URL didn't work in that way as well. I am using a sample code and URL (https://jira.atlassian.com/rest/api/latest/issue/JRA-9.json) on which i am getting a json response but code doesn't work on line final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "admin", "admin");

Below is my code(Source Google).

import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.JiraRestClientFactory;
import com.atlassian.jira.rest.client.NullProgressMonitor;
import com.atlassian.jira.rest.client.domain.BasicIssue;
import com.atlassian.jira.rest.client.domain.BasicProject;
import com.atlassian.jira.rest.client.domain.Comment;
import com.atlassian.jira.rest.client.domain.Issue;
import com.atlassian.jira.rest.client.domain.SearchResult;
import com.atlassian.jira.rest.client.domain.Transition;
import com.atlassian.jira.rest.client.domain.input.FieldInput;
import com.atlassian.jira.rest.client.domain.input.TransitionInput;
import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collection;

public class Example1 {
public static void main(String[] args) throws URISyntaxException {
final JiraRestClientFactory factory = new JerseyJiraRestClientFactory();
final URI jiraServerUri = new URI("https://jira.atlassian.com/rest/api/latest/issue/JRA-9.json");
final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "admin", "admin");
final NullProgressMonitor pm = new NullProgressMonitor();
final Issue issue = restClient.getIssueClient().getIssue("TST-1", pm);

System.out.println(issue);

// now let's vote for it
restClient.getIssueClient().vote(issue.getVotesUri(), pm);

// now let's watch it
restClient.getIssueClient().watch(issue.getWatchers().getSelf(), pm);

// now let's start progress on this issue
final Iterable<Transition> transitions = restClient.getIssueClient().getTransitions(issue.getTransitionsUri(), pm);
final Transition startProgressTransition = getTransitionByName(transitions, "Start Progress");
restClient.getIssueClient().transition(issue.getTransitionsUri(), new TransitionInput(startProgressTransition.getId()), pm);

// and now let's resolve it as Incomplete
final Transition resolveIssueTransition = getTransitionByName(transitions, "Resolve Issue");
Collection<FieldInput> fieldInputs = Arrays.asList(new FieldInput("resolution", "Incomplete"));
final TransitionInput transitionInput = new TransitionInput(resolveIssueTransition.getId(), fieldInputs, Comment.valueOf("My comment"));
restClient.getIssueClient().transition(issue.getTransitionsUri(), transitionInput, pm);

}

private static Transition getTransitionByName(Iterable<Transition> transitions, String transitionName) {
for (Transition transition : transitions) {
if (transition.getName().equals(transitionName)) {
return transition;
}
}
return null;
}

}

 

Nic Brough -Adaptavist-
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.
February 3, 2017

You are using the wrong url.  Your code is irrelevant if you are looking at the wrong url.

Remove the .json

 

Suggest an answer

Log in or Sign up to answer