简体   繁体   English

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

[英]How to Create a Issue into JIRA through REST api?

I am sending the POST request to the JIRA with my json data for create a project, but I am unable to create a project into JIRA, I tried to see the error from the Fiddler and I got following error. 我正在使用我的json数据向JIRA发送POST请求以创建项目,但是我无法在JIRA中创建项目,我试图从Fiddler看到错误并且我得到了以下错误。 I am using the C# and created console application for it. 我正在使用C#并为它创建了控制台应用程序。

My JSON data which I am posting is following. 我发布的我的JSON数据如下。

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

Error Message is following: 错误消息如下:

{"errorMessages":[],"errors":{"issuetype":"issue type is required"}} {“errorMessages”:[],“errors”:{“issuetype”:“问题类型是必需的”}}

I am posting json data from the following code, please suggest what and where I am wrong? 我从以下代码发布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;

In above code you can see I am sending the credentials for Authorize the user and sending the data. 在上面的代码中,您可以看到我正在发送授权用户和发送数据的凭据。

更改您的数据如下:

string data = @"{'fields':{'project':{'key':'JTL'},'summary':'Sample issue','description':'Creating an issue via REST API','issuetype':{'name':'Bug'}}}";

I have solved the my problem. 我解决了我的问题。 I made small changes in my code and my code is working successfully. 我在代码中做了一些小改动,我的代码运行成功。 i changed the url. 我改变了网址。

Old Url: https://MyCompany.atlassian.net/rest/api/2/issue
new url: https://MyCompany.atlassian.net/rest/api/latest/issue

in Json i made small change, in the "issuetype" name was Bug, which is currently not available in my account, currently in my account "TASK" issuetype is available so i changed issutype name from "Bug" to "Task". 在Json我做了一个小改动,在“issuetype”名称是Bug,目前我的帐户中没有,目前在我的帐户“TASK”issuetype是可用的所以我将issutype名称从“Bug”更改为“任务”。 Now its working successfully!, thank god it killed my lot of time. 现在它成功地工作了!感谢上帝它杀了我很多时间。 Sad :( 伤心:(

Thanks Abdurrahman Koken too. 还要感谢Abdurrahman Koken。 :) cheers! :)干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM