如何创建一个问题到JIRA thorugh REST API? [英] How to Create a Issue into JIRA thorugh REST api?

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

问题描述

我发送POST请求到JIRA与我的json数据创建一个项目,但我无法创建一个项目到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:issue type is required}}

{"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 maniputlate 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.

推荐答案

我解决了我的问题。我对我的代码做了小改动,我的代码是成功的。
我改变了url。

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

在issuetype名称是Bug,这是目前无法在我的帐户,目前在我的帐户TASKissuetype是可用的,所以我将issutype名称从Bug更改为任务。现在它的工作成功!,感谢上帝它杀了我很多时间。 Sad:(

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!

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

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