1
votes

I want to get issues from boards and print issues's summary (using JIRA Rest API: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-getIssuesForBoard), but i don't want to get all issue's fields, - i need fields: "sprint" and "epic".

I have error:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

At line:

var response = client.RestClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                        @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");

Code (C#):

var client = Atlassian.Jira.Jira.CreateRestClient(jiraurl, login, password);
var response = client.RestClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                       @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
foreach (var issue in response.issues)
{
     Console.WriteLine(issue.fields.epic.summary);
}

Class ResponseIssues (C#):

public class ResponseIssues
{
    public string expand;
    public int startAt;
    public int maxResults;
    public int total;
    public List<Issue_> issues;
}    
public class Issue_
{
    public string expand;
    public string id;
    public string self;
    public string key;
    public Field fields;
}    
public class Field
{
    public Sprint sprint;
    public Epic epic;            
}   
public class Sprint
{
    public int id;
    public string self;
    public string state;
    public string name;
}    
public class Epic
{
    public int id;
    public string self;
    public string name;
    public string summary;
    public Color color;
    public bool done;
}    
public class Color
{
    public string key;
}
3
You can enable request trace: bitbucket.org/farmas/atlassian.net-sdk/wiki/… Anyway can you please check which values is null? Is it RestClient, response or something else? Maybe you cannot deserialize result into "ResponseIssues" because of some wrong result. - kat1330
@kat1330, everything what in "fileds" i can't get. I try get "description", but i get error: "Object reference not set to an instance of an object." - Se Br

3 Answers

1
votes

It seems like something didn't get initialized properly. Whenever this happens to me, I break up the chain with assignments to try to figure out which object is null. Also catch the exception, and explore it in visual studio. In your case, try this:

try{
  var client = Atlassian.Jira.Jira.CreateRestClient(jiraurl, login, password);
  // Add breakpoint... is client null? There could be an issue with your login, password or the url you've passed. 
  // Or maybe it's Atlassian.Jira.CreateRestClient (instead of Jira.Jira.CreateRestClient), though that should get flagged by the compiler unless there's some recursion or parenting in the Jira namespace
  var restClient = client.RestClient; 
  // Add breakpoint... is restClient null? Could be that CreateRestClient is lazy-loading, in which case I'd look at the url, login and password again.
  var response = restClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                   @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
}
catch(Exception ex)
{
  Console.WriteLine(ex); // Or just breakpoint here and explore the exception.
}
0
votes

Simply Travels "issues"=>"fields" got your "sprint" and "epic".

0
votes
 var response = client.RestClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                        @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
            var jo = JObject.Parse(response);
            var id = jo["issues"]["fields"]['sprint']['id'].ToString();
            var self= jo["issues"]["fields"]['sprint']['self'].ToString();
            var state= jo["issues"]["fields"]['sprint']['state'].ToString();
            var name= jo["issues"]["fields"]['sprint']['name'].ToString();
            Console.WriteLine(id);
            Console.WriteLine(self);
            Console.WriteLine(state);
            Console.WriteLine(name);
            Console.Read();