Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using c# to access jira cloud issues

Bert Lutz October 24, 2016

I am new to JIRA and am trying to access my JIRA cloud issues from c#.  Does anyone have a working example of a c# routine to do this?

Here is a code snippet from some code that I have limping along after installing Atlassian.JIra.dll (v4.0.30319)

var jiraConnection = Atlassian.Jira.Jira.CreateRestClient("http://xxxxx.atlassian.net", "userid", "pwd");
var x = jiraConnection.GetIssue("MT5-13105"); // throws an error;  Invalid Operation: Sequence contains no elements.
var y = jiraConnection.GetIssuePriorities();  // returns expected values
var f = jiraConnection.GetIssueResolutions();  // returns expected values
var d = jiraConnection.GetIssuesFromJql("statusCategory != Done ORDER BY priority DESC");  // returns no values; over 100 expected; this jql was copied from a filter in the UI.
var g = jiraConnection.GetIssueStatuses(); // returns no values; 6 expected

It appears that I am able to connect to my JIRA instance.  Some methods return values others do not.  I'm wondering if there is a security setting that I am not aware of (these are admin credentials).

My goal is to get a list of open issues with a few issue attributes.  Any help is appreciated.

Thanks.

Bert

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Bert Lutz October 25, 2016

Thanks, Nick.

Using RestSharp I was just now able to get a call to work.  I'm posting just a little of the code in case it might help someone else.  One other thing to be aware of:  while user name and email seem to work interchangeably in JIRA cloud, only the user name works in the rest api.  It took me a while to figure that out.

using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient();
client.BaseUrl = new Uri("https://knnc.atlassian.net");
client.Authenticator = new HttpBasicAuthenticator("UserNameNOTemail", "pwd");

var request = new RestRequest(Method.GET);
request.Resource = "rest/api/2/issue/MRR-99028";
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json; charset=utf-8");

request.RequestFormat = DataFormat.Json;

IRestResponse response = client.Execute(request);

Liz Ravenwood et al at BE Aerospace September 26, 2017

Thanks Bert.  I'm trying to cut my teeth on getting data out of JIRA, and have just found RestSharp.  I suppose you would replace the issue number with some JQL to get the data?  How would you put the data in a string or a file or anything you offer to help me move along further is HUGELY appreciated.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 25, 2016

As you've not had a decent answer to this yet, I think you should get at least something to work with.

My C is ancient and I've barely looked at C# since I essentially stopped using Windows in the last millennium.  So, I'm sorry I can't help you with that bit at all.

I also tend not to use the REST client or dll stuff, because I don't need to.  So I can't help you there either.

But, if you can write some C# that can issue a REST call directly to JIRA and read a response, then https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-query-issues can show you both how to construct the content of the call, and what the response will be.  For your search, you probably need to hit https:/xxxxx.atlassian.net/rest/api/2/search?jql=status=open

 

TAGS
AUG Leaders

Atlassian Community Events