Search code examples
asp.net-mvcmodel-view-controllerjira-rest-apiatlassian-plugin-sdk

C# JIRA SDK Unclear Error in SaveChanges() Function


I'm trying to create a web form where I can dynamically create a JIRA Epic using whatever the user inputs. I'm relying on the Atlassian JIRA SDK Nuget package to do so.

Here's the function as it stands right now.

public ActionResult Create(string title, string description)
{
    Jira jiraConnection = Jira.CreateRestClient("https://xxxx.atlassian.net/", "username", "password");
    Issue issueMain = jiraConnection.CreateIssue("xxxx");
    issueMain.Type = "Epic";
    issueMain.Priority = "Major";
    issueMain.Summary = title;
    issueMain.Description = description;

    try
    {
        issueMain.SaveChanges();
    }
    catch (Exception ex)
    {
         MessageBox.Show(ex.InnerException.Message.ToString());
         return View("Contact");
    }

    return RedirectToAction("Index");            
}

I've come across a few different errors in trying to get the issue actually created, but the one currently plaguing me is this:

error CS0103: The name 'client' does not exist in the current context

I hit this error when I hit the issueMain.SaveChanges() line, and I don't know why, because I'm not instantiating a "client" variable anywhere in this function and I can't step into the SaveChanges function to see where it might be getting referenced within it.

When I check the inner exception, I see that I'm getting an Encountered a 401 - Unauthorized error while loading this page error, which I also don't understand, as I am providing the credentials I would usually use to log in to our JIRA site.


Solution

  • I have found the link to the Atlassian Jira SDK documentation: https://bitbucket.org/farmas/atlassian.net-sdk/wiki/Home

    It looks like you need to add the two propertiesType and Priority when creating the issue.

    issueMain.Type = "Bug"; issueMain.Priority = "Major";