如何通过REST API向JIRA创建问题? [英] How to Create a Issue into JIRA through REST api?

查看:363
本文介绍了如何通过REST API向JIRA创建问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用json数据将POST请求发送到JIRA,以创建一个项目,但是我无法在JIRA中创建一个项目,我试图从Fiddler看到错误,但遇到了以下错误。我正在使用C#并为此创建了控制台应用程序。

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. I am using the C# and created console application for it.

我正在发布的JSON数据如下。

My JSON data which I am posting is following.

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

错误消息如下:


{ errorMessages:[], errors: { issuetype:必须为问题类型}}

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

我正在从以下代码中发布json数据,请提出建议以及我错了吗?

I am posting json data from the following code, please suggest what and where I am wrong?

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;

在上面的代码中,您可以看到我正在发送用于授权用户的凭据并发送数据。 / p>

In above code you can see I am sending the credentials for Authorize the user and sending the data.

推荐答案

我已经解决了我的问题。我对代码进行了少量更改,并且代码成功运行。
我更改了网址。

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

在杰森一世进行了较小的更改,问题类型名称中的错误是Bug,当前在我的帐户中不可用,当前在我的帐户中任务是可用的问题类型,所以我将问题类型名称从错误更改为任务。现在它的工作成功了!感谢上帝,这浪费了我很多时间。伤心:(

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". Now its working successfully!, thank god it killed my lot of time. Sad :(

也感谢Abdurrahman Koken。:)欢呼!

Thanks Abdurrahman Koken too. :) cheers!

这篇关于如何通过REST API向JIRA创建问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆