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

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

0 vote

The example you've found looks wrong to me.

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

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;
}

}

 

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Marketplace Apps

Tips on how to choose the best estimation method for your planning

Planning and grooming sessions all come with their own sets of rules. Team members meet to estimate stories or other work items, all according to an agreed-upon process. And with every session comes ...

74 views 0 11
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you