0

我正在使用 Google Apps 脚本修改 Clockify ( https://clockify.me/developers-api ) 中的项目。我收到错误消息“无法将文本解析为持续时间”。

当前代码(请注意,真正的目标是从当前工作表的 M3 单元格中恢复信息,但出于测试目的,我已将其注释掉):

function ClockifyEstimateUpdate() {
// Step 1: Find ProjectID for this file
  var sheet = ss.getActiveSheet();
  var FileNo = sheet.getSheetName();
  var url = 'https://api.clockify.me/api/v1/workspaces/'+cifyWorkspace+'/projects?name='+FileNo;
  var response = UrlFetchApp.fetch(url, cifyHeader);
  var json = response.getContentText();
  var data = JSON.parse(json);
  var PID = data[0]["id"];

//Step 2: Use M3 to Set Estimate
  //var estimate = sheet.getRange("M3");
  var estimate = '3000';
  var payload = JSON.stringify({'timeEstimate' : {'estimate' : estimate, 'type': "MANUAL", 'active': "true", 'resetOption': "null"}});
  //var payload = JSON.stringify({'timeEstimate' : {'estimate' : estimate, 'type': "MANUAL", 'active': "true", 'resetOption': "null"}, 'budgetEstimate' : {'estimate' : '0', 'type': "MANUAL", 'active': "false", 'resetOption': "null"}});
  var clockifyoptions = {
  'muteHttpExceptions' : true,
  'method' : 'patch',
  'headers' : cifyHeaders,
  'payload' : payload
  };
  var response2 = UrlFetchApp.fetch('https://api.clockify.me/api/v1/workspaces/'+cifyWorkspace+'/projects/'+PID+'/estimate', clockifyoptions);
  Logger.log(response2);
}

记录的错误:

{"message":"无法读取文档:无法构造 com.clockify.adapter.http.project.TimeEstimateWithOptionsRequest 的实例,问题:无法将文本解析为 Duration\n 在 [Source: java.io.PushbackInputStream@44d0391a ; line: 1, column: 89] (通过引用链: com.clockify.adapter.http.project.ProjectEstimateRequest["timeEstimate"]); 嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException: 无法构造实例com.clockify.adapter.http.project.TimeEstimateWithOptionsRequest,问题:文本无法解析为 [Source: java.io.PushbackInputStream@44d0391a; line: 1, column: 89] 处的 Duration\n(通过引用链:com. clockify.adapter.http.project.ProjectEstimateRequest["timeEstimate"])","code":3002}

我已经尝试将估计设置为“3000s”,就像其他地方提出的那样。到目前为止,这并不能解决问题。我需要对估计变量进行某种解析吗?

谢谢。

4

1 回答 1

0

Got it. The answer was in the example in the Clockify API Documentation.

The example called for a time estimate in the form "PT1H0M0S". This is ISO-8601. I needed to send my request in that format.

于 2021-02-18T15:34:21.303 回答