N0xus
N0xus

Reputation: 2724

JIRA C# SDK Connecting to JIRA

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 relating to any of the 3 errors or what sort of syntax it is expecting. I would investigate the bitbucket more, but my works firewall has it blocked for unknown reasons.

Does anyone have any experience on combating these errors?

Upvotes: 5

Views: 13116

Answers (2)

HeavyDNickell
HeavyDNickell

Reputation: 76

Not C# ... but this is how you can communicate with Atlassian. This example is from a Google Sheet (Just change the URL and endpoints). I've done this a lot through VBA too over the years. It seems like lately, the user / password has to be encoded. I don't recall that being the case from earlier versions

function showAtlassian() {
  var html = HtmlService.createHtmlOutputFromFile('atlassianform')
      .setWidth(200)
      .setHeight(200);
  SpreadsheetApp.getUi().showModalDialog(html, 'Atlassian Login');
}

function processAtlassian(myForm) {
  var username = myForm.un;
  var userpw = myForm.pw;
  var myencoded = Utilities.base64Encode(username+":"+userpw);
  var headers = {"Authorization" : "Basic " + myencoded};
  var options = {
      'method': 'get',
      "contentType" : "application/json",
      "headers": headers,
      'muteHttpExceptions': false
    }
var ui = SpreadsheetApp.getUi(); // Same variations.
url = 'https://---your domain---/wiki/rest/api/user/current';
  try {
    var response = UrlFetchApp.fetch(url, options);
    var data = JSON.parse(response)
    var result = ui.alert( 'got valid connection userkey ' + data.userKey );
  } catch(error) {
    var result = ui.alert( 'invalid user or password: url: '+ url +' err: ' + error.toString());
    getatlassian();
  }
}

function getatlassian() {
  var ui = SpreadsheetApp.getUi();
  showAtlassian()
}

Upvotes: 1

Neil
Neil

Reputation: 11889

As the prototype for Jira is:

Jira(ServiceLocator services, JiraCredentials credentials = null, JiraCache cache = null)

Then the errors you are getting are correct (strings are not JiraCredentials). So either you need to create some credentials or you could use the other function:

public static Jira CreateRestClient(string url, string username = null, string password = null, JiraRestClientSettings settings = null)

So, something like:

Jira jira = Jira.CreateRestClient(url, "admin", "password");

Upvotes: 7

Related Questions