Search code examples
google-apps-scriptclickup-api

Why does this task update on ClickUp show 200 as response, but the update doesn't occur using GAS?


Their documentation example requires certain fields to be in the update body, but these values aren't always available. I've checked some instructions and this, for example, says that you only need to pass the one that you want to update, which is what I am doing. Keep getting 200, but the update doesn't actually happen.

const clickupToken = "***"
const clickupReqBody = { "Authorization": clickupToken }
const clickupUrl = "https://api.clickup.com/api/v2/"

function updateTaskStatusClickUp(updatedTaskData, taskId) {
  taskid = '476ky1';
  
  updatedTaskData = {
    "status": "COMPLETE"
  }
  
  const query = {
    custom_task_ids: 'false',
    team_id: '',
  };

  const resp = UrlFetchApp.fetch(
    clickupUrl + `task/` + `${taskId}?${query}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json',
        Authorization: clickupToken
      },
      body: JSON.stringify(updatedTaskData)
    }
  );
  console.log(resp.getContentText());
}

Appreciate your help!


Solution

  • It turns out that the body needs to be payload: JSON.stringify(), as clarified by Google Apps Script legend, in the question comments above.

    const clickupToken = "***"
    const clickupReqBody = { "Authorization": clickupToken }
    const clickupUrl = "https://api.clickup.com/api/v2/"
    
    function updateTaskStatusClickUp(updatedTaskData, taskId) {
      taskid = '476ky1';
      
      updatedTaskData = {
        "status": "COMPLETE"
      }
      
      const query = {
        custom_task_ids: 'false',
        team_id: '',
      };
    
      const resp = UrlFetchApp.fetch(
        clickupUrl + `task/` + `${taskId}?${query}`, {
          method: 'PUT',
          headers: {
            'Content-Type': 'application/json',
            Authorization: clickupToken
          },
          payload: JSON.stringify(updatedTaskData)
        }
      );
      console.log(resp.getContentText());
    }