Forums

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

Atlassian SDK for C# - getting and processing a response?

HH
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.
July 3, 2019

0

I have installed the atlassian sdk and I am now following the documentation to try and query the tickets:

https://bitbucket.org/farmas/atlassian.net-sdk/wiki/Home

The docs show this:

 // create a connection to JIRA using the Rest client
 var jira = Jira.CreateRestClient("http://<your_jira_server>", "<user>", "<password>");

 // use LINQ syntax to retrieve issues
 var issues = from i in jira.Issues.Queryable
              where i.Assignee == "admin" && i.Priority == "Major"
              orderby i.Created
              select i;

I have the code listed below this but I am entering the catch statement with the following error (it;s much bigger - this is just the first part of it!)

System.AggregateException: One or more errors occurred. ---> Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Atlassian.Jira.Remote.RemoteField[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path '', line 1, position 2. at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal

So I think the way that I'm trying to retrieve the results through the foreach loop is incorrect?

foreach (var issue in issues)
            {                results.InnerHtml += (issue.Key.Value + " -- " + issue.Summary);
            }

But I'm really stuck as to how to retrieve them. Any help would be welcome! I'm a bit stumped!

Full code sample:

namespace JIRA_service_desk{
public partial class WebForm3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        var jira = Jira.CreateRestClient("https://myurl.co.uk", "username", "pwd");

        var issues = from i in jira.Issues.Queryable
                     where i.Assignee == "bob"
                     orderby i.Created
                     select i;

        try
        {
            foreach (var issue in issues)
            {                results.InnerHtml += (issue.Key.Value + " -- " + issue.Summary);
            }
        }
        catch(Exception ex)
        {            results.InnerHtml = ex.ToString();
        }

        //results.InnerHtml = issues.ToString();
    }
}
}

1 answer

0 votes
Fabian Lim
Community Champion
October 9, 2021

Hi HH,

Try posting this in the dev community: https://community.developer.atlassian.com/

Regards 

Suggest an answer

Log in or Sign up to answer