0

I'm using Google Apps Script to modify projects in Clockify (https://clockify.me/developers-api). I'm getting the error, "Text cannot be parsed to a duration".

Current code (note that the real goal is to recover the information from the current sheet's M3 cell, but for testing purposes I've commented that out):

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);
}

Error as logged:

{"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}

I've tried setting estimate as '3000s' as has been proposed elsewhere. So far, this does not fix the problem. Do I need some sort of parsing of the estimate variable?

Thanks.

Databoy2k
  • 123
  • 1
  • 12
  • Specific information on this particular method at https://clockify.me/developers-api#operation--v1-workspaces--workspaceId--projects-patch-estimate – Databoy2k Feb 17 '21 at 20:04
  • 1
    Can I ask you about your question? 1. About the error of `Text cannot be parsed to a duration`, where is the error occurs in your script? 2. Can I ask you about the values of `cifyHeader` and `cifyHeaders`? If the values include your personal information, please replace it with others. – Tanaike Feb 18 '21 at 00:44
  • The error gets logged as the variable response2. It's printing via Logger.log at the end. cifyHeader and cifyHeaders are two different ways of passing the API key in the request. I don't know why they're required to be different, but they are. They work, though - I'm using basically this code to start timers in clockify already. – Databoy2k Feb 18 '21 at 15:16

1 Answers1

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.

Databoy2k
  • 123
  • 1
  • 12