c# - 将工作日志发布到 JIRA 时需要哪些字段?

标签 c# post jira-rest-api

我想通过 API 发布 CSV 数据,以编程方式填充我的 JIRA 数据库。我有 URL 和身份验证工作,但我总是收到 400 错误:“错误请求”。我的猜测是我在有效负载中遗漏了一些必填字段:

{
"comment": "test",
"self": "https://jira.mycompany.com/rest/api/latest/issue/12345",
"started": "2015-12-09T17:29:14.698-0500",
"timeSpent": "1 s",
"timeSpentSeconds": "1"
}

The documentation has an example , 但它包含一些似乎不适用于 POST 的字段,例如工作日志 ID - 它肯定必须由服务器而不是客户端创建。 query 参数都是可选的。

One user claims只需三个字段即可获得成功:commentstartedtimeSpent。我仍然只得到那些字段的 400。 Another调整时间格式后也是如此;我匹配他或她的格式。 Other users可以使用 commentstartedtimeSpentSeconds 进行 POST。

一个常见的问题是适本地设置内容类型;我相信我已经涵盖了这一点,因为如果我使用“application/json”以外的类型,我会收到 415“不支持的媒体类型”。

我听说有一个特定的产品需要使用 API 进行写入(与读取相反,后者工作正常)。但是,如果我们缺少该许可证,我希望收到一条错误消息。

这是代码,为了调试有点冗长:

// Initialize various parameters
string  url        = baseUrl + "issue/" + issueKey + "/worklog";
var     rawContent = // Double-quote and concatenate parameters, and wrap them in curly brackets
var     client     = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", encodedCreds);
var     content    = new StringContent(rawContent, Encoding.UTF8, "application/json");

// Using POST gives a 400 Bad Request error; are we missing a required field?
var  task     = client.PostAsync(url, content);  task.Wait();
var  response = task.Result;

我是否缺少必填字段?如果我 POST 时没有内容或字段名称无效,则返回的错误没有变化。如果 JIRA 能够屈尊告诉我它期望但未获得或获得但未期望的字段,那就太好了。

Very similar, but focused on 500 errors.

最佳答案

问题不在于以下字段之一:commentstartedtimeSpentSeconds 实际上就足够了。相反,问题是我只用了一秒钟的时间进行测试。显然,JIRA 希望以至少一分钟为单位记录工作,即使它明确跟踪 timeSpentSeconds!

这是尝试使用(例如)"timeSpentSeconds": 30" 上传时会收到的确切错误消息:

"errorMessages" : ["Worklog must not be null."],
"errors" :
    {
    "timeLogged" : "You must indicate the time spent working."
    }

但是,我能够成功上传这个主体的作品:

{ 
"comment": "test",
"started": "2015-12-10T13:45:01.778-0500",
"timeSpentSeconds": "60"
}

对于 future 的访问者:我最终放弃了这种方法,因为写入工作日志总是记录在你自己的帐户下。管理员不能使用 API 为其他人记录工作,只能为他或她自己记录工作。

关于c# - 将工作日志发布到 JIRA 时需要哪些字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34191414/

相关文章:

c# - 折叠重复和半重复记录的代码?

c# - Web API 将输入转换为随机 int

php - 我应该如何处理使用 PHP 提交非常大的字符串?

asp.net - 如何通过门户中的注销按钮从所有打开的 Web 应用程序中注销?

jira - TeSTLink 创建 Jira 问题版本字段

c# - Powershell 到 C# 语法转换

c# - 为什么不能在 Nullable<T> 简写上调用静态方法?

c# - 如何从json对象中获取key并转换为数组?

java - 如何区分项目的问题,同时检索所有项目的所有问题?

php - 将 jira API 响应转换为 HTML