API 中的文本无法解析为持续时间错误
Text Cannot be Parsed to a Duration error from API
我正在使用 Google Apps 脚本修改 Clockify (https://clockify.me/developers-api) 中的项目。我收到错误消息,“无法将文本解析为持续时间”。
当前代码(请注意,真正的目标是从当前 sheet 的 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":"Could not read document: Can not construct instance of
com.clockify.adapter.http.project.TimeEstimateWithOptionsRequest,
problem: Text cannot be parsed to a Duration\n at [Source:
java.io.PushbackInputStream@44d0391a; line: 1, column: 89] (through
reference chain:
com.clockify.adapter.http.project.ProjectEstimateRequest["timeEstimate"]);
nested exception is
com.fasterxml.jackson.databind.JsonMappingException: Can not construct
instance of
com.clockify.adapter.http.project.TimeEstimateWithOptionsRequest,
problem: Text cannot be parsed to a Duration\n at [Source:
java.io.PushbackInputStream@44d0391a; line: 1, column: 89] (through
reference chain:
com.clockify.adapter.http.project.ProjectEstimateRequest["timeEstimate"])","code":3002}
我试过按照其他地方的建议将估算值设置为“3000 秒”。到目前为止,这并不能解决问题。我需要对估计变量进行某种解析吗?
谢谢。
知道了。答案在 Clockify API 文档中的示例中。
该示例要求以“PT1H0M0S”的形式进行时间估算。这是 ISO-8601。我需要以那种格式发送我的请求。
我正在使用 Google Apps 脚本修改 Clockify (https://clockify.me/developers-api) 中的项目。我收到错误消息,“无法将文本解析为持续时间”。
当前代码(请注意,真正的目标是从当前 sheet 的 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":"Could not read document: Can not construct instance of com.clockify.adapter.http.project.TimeEstimateWithOptionsRequest, problem: Text cannot be parsed to a Duration\n at [Source: java.io.PushbackInputStream@44d0391a; line: 1, column: 89] (through reference chain: com.clockify.adapter.http.project.ProjectEstimateRequest["timeEstimate"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.clockify.adapter.http.project.TimeEstimateWithOptionsRequest, problem: Text cannot be parsed to a Duration\n at [Source: java.io.PushbackInputStream@44d0391a; line: 1, column: 89] (through reference chain: com.clockify.adapter.http.project.ProjectEstimateRequest["timeEstimate"])","code":3002}
我试过按照其他地方的建议将估算值设置为“3000 秒”。到目前为止,这并不能解决问题。我需要对估计变量进行某种解析吗?
谢谢。
知道了。答案在 Clockify API 文档中的示例中。
该示例要求以“PT1H0M0S”的形式进行时间估算。这是 ISO-8601。我需要以那种格式发送我的请求。