You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I'm using the Atlassian SDK from the following location: https://bitbucket.org/farmas/atlassian.net-sdk
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: https://www.codeproject.com/Tips/762516/Connecting-to-Jira-using-Csharp
In the above link, he connects to JIRA using the following line:
Jira jiraConn = new Jira("http://yourjiraurl.com/", 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?
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 https://docs.atlassian.com/jira/REST/cloud/#api/2 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")
{
try
{
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()))
{
writer.Write(data);
}
}
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);
throw;
}
}
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @santhosh.gs
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.