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

What fields are required when POSTing a worklog to JIRA?

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

{
"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 - 它肯定必须由服务器而不是客户端创建。 查询参数都是可选的。

One user claims to have success with just three fields: comment, started, and timeSpent. I still get a 400 with just those fields. Another did the same, after adjusting the time format; I'm matching his or her format. Other users 可以 POST 使用 commentstartedtimeSpentSeconds

一个常见的问题是适当地设置内容类型;我相信我已经涵盖了这一点,因为如果我使用 "application/json".

以外的类型,我会得到 415 "Unsupported Media Type"

我听说需要特定的产品才能使用 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"
}

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