Skip to content

Instantly share code, notes, and snippets.

@gandarez
Created August 25, 2016 13:29
Show Gist options
  • Save gandarez/50040e2f94813d81a15a4baefba6ad4d to your computer and use it in GitHub Desktop.
Save gandarez/50040e2f94813d81a15a4baefba6ad4d to your computer and use it in GitHub Desktop.
Example of creating an issue on Jira using Restsharp
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Jira
using RestSharp;
using RestSharp.Authenticators;
namespace Jira
{
class Program
{
static void Main(string[] args)
{
var client = new RestClient("http://{URL}/rest/api/2");
var request = new RestRequest("issue/", Method.POST);
client.Authenticator = new HttpBasicAuthenticator("user", "pass");
var issue = new Issue
{
fields =
new Fields
{
description = "Issue Description",
summary = "Issue Summary",
project = new Project { key = "KEY" },
issuetype = new IssueType { name = "ISSUE_TYPE_NAME" }
}
};
request.AddJsonBody(issue);
var res = client.Execute<Issue>(request);
if (res.StatusCode == HttpStatusCode.Created)
Console.WriteLine("Issue: {0} successfully created", res.Data.key);
else
Console.WriteLine(res.Content);
}
}
public class Issue
{
public string id { get; set; }
public string key { get; set; }
public Fields fields { get; set; }
}
public class Fields
{
public Project project { get; set; }
public IssueType issuetype { get; set; }
public string summary { get; set; }
public string description { get; set; }
}
public class Project
{
public string id { get; set; }
public string key { get; set; }
}
public class IssueType
{
public string id { get; set; }
public string name { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment