我想通过 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只需三个字段即可获得成功:comment
、started
和 timeSpent
。我仍然只得到那些字段的 400。 Another调整时间格式后也是如此;我匹配他或她的格式。 Other users可以使用 comment
、started
和 timeSpentSeconds
进行 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 能够屈尊告诉我它期望但未获得或获得但未期望的字段,那就太好了。
最佳答案
问题不在于以下字段之一:comment
、started
和 timeSpentSeconds
实际上就足够了。相反,问题是我只用了一秒钟的时间进行测试。显然,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/