无法更新Zoho Projects任务工时问题排查求助
问题排查与解决方案
核心问题点及修复步骤
1. HTTP请求方法错误
Zoho Projects的任务更新接口要求使用PUT方法(POST多用于创建资源),修改invokeurl中的请求类型:
type :PUT
2. working_hours数据类型不匹配
你将计算后的数值转成了字符串(calc.concat("")),但API要求传入数值类型(整数/浮点数),直接传入计算结果即可:
owner_map.put("working_hours", calc);
3. API端点路径错误
原URL结尾缺少更新动作的标识,根据Zoho Projects API规范,正确的更新任务端点应为/tasks/{taskId}/update,调整URL:
url :projectsDomainURL + "/portal/" + portalId + "/projects/" + projectId + "/tasks/" + taskId + "/update"
4. 空值处理增强
如果自定义字段Proposed Hours无值,proposed_hours.toLong()会抛出异常,增加空值判断:
calc = 0; if (!proposed_hours.isNull() && !proposed_hours.isEmpty()) { calc = proposed_hours.toLong() / no_of_owners; }
修复后的完整脚本
owners = testResponse.getJson('tasks').getJSON("details").getJSON("owners"); no_of_owners = owners.size(); custom_fields = testResponse.getJson('tasks').getJSON('custom_fields'); proposed_hours = ""; for each item in custom_fields { if(item.getJson('label_name') == "Proposed Hours") { proposed_hours = item.getJson("value"); } } value_update = Map(); owner_work = List(); for each owner in owners { owner_map = Map(); owner_map.put("user_id",owner.getJson('id')); // 空值安全处理 calc = 0; if (!proposed_hours.isNull() && !proposed_hours.isEmpty()) { calc = proposed_hours.toLong() / no_of_owners; } owner_map.put("working_hours", calc); owner_work.add(owner_map); } value_update.put("owner_work", owner_work); update_response = invokeurl [ url :projectsDomainURL + "/portal/" + portalId + "/projects/" + projectId + "/tasks/" + taskId + "/update" type :PUT parameters:value_update connection:"*********" ]; info update_response;
验证建议
- 查看
info update_response的输出,确认API返回的具体响应,是否存在权限或参数错误提示 - 检查
proposed_hours和calc的日志输出,确认数值计算逻辑正确 - 确保
connection对应的授权账号拥有任务工时更新权限
内容的提问来源于stack exchange,提问作者lewstherinth
相关产品推荐
相关产品推荐

