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

时间:2015-12-10 00:05:14

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

One user claims仅使用三个字段取得成功:commentstartedtimeSpent。我仍然只有那些领域得到400。调整时间格式后Another做了同样的事情;我匹配他或她的格式。 Other users可以使用commentstartedtimeSpentSeconds进行发布。

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

我听说使用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.

1 个答案:

答案 0 :(得分:6)

问题不是字段之一: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​​为其他人记录工作,仅限他或她自己。

相关问题