Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Connecting to JIRA via C# rest api

I'm using the Atlassian SDK from the following location: 


Right now, I'm simply trying to connect to my JIRA and just bring down some basic information like my tasks. Doing a quick google I found the following example:

In the above link, he connects to JIRA using the following line:

Jira jiraConn = new Jira("", jUserID, jPassword);

But when I try the same line:

 Jira jira = new Jira(url, "admin", "password");

I get the following errors: 

cannot convert from 'string' to 'Atlassian.Jira.ServiceLocator'

cannot convert from 'string' to 'Atlassian.Jira.JiraCredentials'

cannot convert from 'string' to 'Atlassian.Jira.JiraCache'

I've looked around to try and find some documentation on this, but I can't find anything. Does anyone have any experience on combating these errors?

4 answers

1 accepted

3 votes
Answer accepted

Hi Sean

You need to install the nuget package mentioned in the link, which should then give you access to the Jira object.

Alternatively, I use the code below which works well. RunQuery is called with only the first parameter passed in, the others are used for Posting data back to Jira. It calls GetEncodedCredentials which requires your password and username (it was username until recently, now it requires your e-mail address, although I haven't renamed the variable). The query passed in to RunQuery is obtained from or similar - remember to prepend it with your jira URL


public static string RunQuery(string query, string argument = null, string data = null, string method = "GET")
m_BaseUrl = query;
HttpWebRequest newRequest = WebRequest.Create(m_BaseUrl) as HttpWebRequest;
newRequest.ContentType = "application/json";
newRequest.Method = method;

if (data != null)
using (StreamWriter writer = new StreamWriter(newRequest.GetRequestStream()))

string base64Credentials = GetEncodedCredentials();
newRequest.Headers.Add("Authorization", "Basic " + base64Credentials);

HttpWebResponse response = newRequest.GetResponse() as HttpWebResponse;

string result = string.Empty;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
result = reader.ReadToEnd();

newRequest = null;
response = null;

return result;
catch (Exception)
//MessageBox.Show(@"There is a problem getting data from Jira :" + "\n\n" + query, "Jira Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

private static string GetEncodedCredentials()
string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
return Convert.ToBase64String(byteCredentials);

We are unable to connect using create CreateRestClient and it says it deprecated for basic authentication with user id and password . Is there any code snippet to replace this for c# ?


You should be able to use the same code, just replace the user id with your email address that you log in to Jira with and replace the password with an API token created using the same email address. For further info on API tokens, see this doc 

Stan St I'm New Here Apr 25, 2022

Did you succeed? I use Atlassian.SDK 8.6.0 library for .NET and get Unathorized 401 when passing username+token. It is fine when I pass username+password.

I'm working with this in VB and I don't know all the ins and out of C# accessibility modifiers.  I think what you want is Jira.CreateClient which has the signature we're looking for.  The documentation leaves a lot to be desired, so I just downloaded the source and worked it backwards using the unit tests.  

Since it's static I don't think you need to use the "new" keyword.

/// <summary>
/// Creates a JIRA rest client.
/// </summary>
/// <param name="url">Url to the JIRA server.</param>
/// <param name="username">Username used to authenticate.</param>
/// <param name="password">Password used to authenticate.</param>
/// <param name="settings">Settings to configure the rest client.</param>
/// <returns>Jira object configured to use REST API.</returns>
public static Jira CreateRestClient(string url, string username = null, string password = null, JiraRestClientSettings settings = null)
var services = new ServiceLocator();
settings = settings ?? new JiraRestClientSettings();
var jira = new Jira(services, new JiraCredentials(username, password), settings.Cache);
var restClient = new JiraRestClient(services, url, username, password, settings);

ConfigureDefaultServices(services, jira, restClient);

return jira;

 Versus what you're doing (and the documentation appears to be showing)

/// <summary>
/// Create a client that connects with a JIRA server with specified dependencies.
/// </summary>
public Jira(ServiceLocator services, JiraCredentials credentials = null, JiraCache cache = null)
_services = services;
_credentials = credentials;
_cache = cache ?? new JiraCache();

this.Debug = false;

 As an aside, the last time I worked with this library (several years ago)  your example would've worked.  I think the documentation (what tiny bit there is) is out of date.  

I am using the same method which is CreateRestClient.

I am getting the results when using http jira url but it's not working when using https urls. 

0 votes

This "jira" object you are creating here must come from a library or import somewhere.  You'll need to consult the docs for that to see what you need to feed into it.

There isn't any documents for this. 

I'm a bit stuck then.  You need to know what to pass into this object and how to create those things, but if the library providing the object isn't documented, there's not a lot you can do.

I got the same issue, did you manage to find a fix for it?

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you