1
votes

I'm trying to get issues from JIRA cloud like below:

 public List<Issue> GetIssues(
        string jql,
        List<string> fields = null,
        int startAt = 0,
        int maxResult = 50)
    {
        fields = fields ?? new List<string> { "summary", "status", "assignee" };

        SearchRequest request = new SearchRequest();
        request.Fields = fields;
        request.JQL = jql;
        request.MaxResults = maxResult;
        request.StartAt = startAt;

        string data = JsonConvert.SerializeObject(request);

this gives "data" as below:

{"jql":"project = CI","startAt":0,"maxResults":50,"fields":["summary","status","assignee"]}

Then, I'm calling run query like below:

string result = runQuery(JiraResource.search, data, "POST");

//run query defination:

 public string runQuery(
        JiraResource resource,
        string argument = null,
        string data = null,
        string method = "GET")
    {
        string url = string.Format("{0}{1}",str_baseURL,resource.ToString()); //This is my URL : https://clientname.atlassian.net/rest/api/2/search

       // string url = string.Format("{0}{1}/", str_baseURL);
        if(argument != null) // as my argument is not null here , so my url is now below
        {

            url = string.Format("{0}{1}/",url,argument); //https://clientname.atlassian.net/rest/api/2/search{"jql":"project =               CI","startAt":0,"maxResults":50,"fields":["summary","status","assignee"]}/
        }
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        request.ContentType = "application/json";
        request.Method = method;
        /*if (data != null) //for time being commented it, becoz of error
        {
            using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
            {
                writer.Write(data);
            }
        }*/
        string base64Credentials = GetEncodedCredentials();
        request.Headers.Add("Authorization", "Basic " + base64Credentials);
        HttpWebResponse response = request.GetResponse() as HttpWebResponse; //Here Im getting "Remote server returned an error(500) Internal server error"
        string result = string.Empty;
        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
        { result = reader.ReadToEnd(); }

        return result;
    }

What I'm doing wrong? Please note that, my other method like "GetProjects" is working fine and I'm getting JSON. Please guide me.

2

2 Answers

0
votes

If you're making a request to a server hosted by Atlassian (as it appears you are), then a 500 Internal Server Error response indicates a problem at Atlassian's end, not yours. I would recommend contacting Atlassian for support.

0
votes

Issue resolved: I made it like this:

 string url = string.Format("{0}{1}", str_baseURL, resource.ToString());
        if (argument != null)
        {
            method = "POST";
            //url = string.Format("{0}{1}/", url, argument); 
        }
        else
        {
            method = "GET";
        }
        data = argument;
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        request.ContentType = "application/json";
        request.Method = method;

It was the issue with "when to use POST and when GET".