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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

190 views 18 7
Join discussion

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