我正在尝试为JIRA软件中的问题添加工作日志,但我收到了错误请求。
有谁知道可能是什么问题?
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders
.Authorization = new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
convertStringtoByteArray(
userName,
userPassword)));
var json = Newtonsoft.Json.JsonConvert.SerializeObject(
new
{
comment = "I did some work here.",
started = "2017-08-17T10:52:10.475+0000",
timeSpentSeconds = 12000
};
var content = new StringContent(json, Encoding.UTF8, "application/json");
var apiUrl = "https://<ACCOUNT>.atlassian.net/rest/api/2/issue/{KEY}/worklog"
var result = httpClient .PostAsync(apiUrl, content).Result;
提前致谢!
答案 0 :(得分:0)
您的实例可能也需要visibility
字段。
根据Jira Rest API docs 样品申请是:
{
"comment": "I did some work here.",
"visibility": {
"type": "group",
"value": "jira-developers"
},
"started": "2017-07-31T14:11:53.507+0000",
"timeSpentSeconds": 12000
}
您可以添加visibility
值并检查吗?
答案 1 :(得分:0)
字符串转换是个问题,请尝试这样
JObject workLogObject = new JObject(
new JProperty("comment", jiraText),
new JProperty("started", strDate),
new JProperty("timeSpentSeconds", seconds));
使用format选项创建字符串
var workLogData = workLog.ToString(Newtonsoft.Json.Formatting.Indented);
var content = new StringContent(workLogData, Encoding.UTF8, "application/json");
传递内容
var result = httpClient .PostAsync(apiUrl, content).Result;