c# – 如何通过REST api向JIRA创建问题?

我正在使用我的json数据向JIRA发送POST请求以创建项目,但是我无法在JIRA中创建项目,我试图从Fiddler看到错误并且我得到了以下错误.我正在使用C#并为它创建了控制台应用程序.

我发布的我的JSON数据如下.

{
 "fields": {
     "project": {
         "key": "JTL"
     },
     "issuetype": {
         "name": "BUG"
     }
  }
}

错误消息如下:

{“errorMessages”:[],”errors”:{“issuetype”:”issue type is required”}}

我从以下代码发布json数据,请提出我错在哪里和哪里?

string data=@"{"fields":{"project":{"key":"JTL"},"issuetype":{"name":"BUG"}}}";

//object of HttpClient.
HttpClient client = new HttpClient();

//Putting URI in client base address.
client.BaseAddress = new Uri(uri);

//Putting the credentials as bytes.
byte[] cred = UTF8Encoding.UTF8.GetBytes("jiraUserName" + ":" + "JiraPassword");

//Putting credentials in Authorization headers.
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));

//Putting content-type into the Header.
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

//I am using StringContent because I am creating console application, no any serialize I used for manipulate the string.
var content = new StringContent(data, Encoding.UTF8, "application/json");

//Sending the Post Request to the server. But getting 400 bad Request.
System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;

在上面的代码中,您可以看到我正在发送授权用户和发送数据的凭据.

解决方法:

更改您的数据如下:

string data = @"{'fields':{'project':{'key':'JTL'},'summary':'Sample issue','description':'Creating an issue via REST API','issuetype':{'name':'Bug'}}}";
上一篇:捕获jira-python异常


下一篇:使用jira-python进行基本身份验证