5

I want to retrieve tasks in a specified status from a list in Clickup but I keep getting an empty response.

Resources - https://jsapi.apiary.io/apis/clickup20/reference/0/tasks/get-tasks.html In the api documentation, it says you can query by status using an array of statuses. Here's my code.

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


function getTasks() {
  var listId = "******";
  var statusArray = ["Backlog","Open"];
  var encodedStatusArray = encodeURIComponent(statusArray)
  var urlAddition = "list/" + listId + "/task?archived=false&subtasks=true&statuses%5B%5D=" + encodedStatusArray
  var params = {
    "urlAddition": urlAddition,
    "method": "GET"
  }
  var res = fetchClickupObject(params)
  Logger.log(res)
}

function fetchClickupObject(params) {
  var url = clickupUrl + params.urlAddition;
  Logger.log(params)
  var response = UrlFetchApp.fetch(url, {
    "headers": clickupReqBody,
    "method": params.method
  });
  return response;
}

I've tried all upper, lower, and proper casing for the statuses.

When I log res it returns {"tasks":[]} even though there are tasks in both the Backlog and Open statuses on clickup.

Tim Post
  • 33,371
  • 15
  • 110
  • 174
jdavis
  • 429
  • 6
  • 16
  • Where does the clickuptoken get defined – Cooper Mar 02 '21 at 15:14
  • I've added a variable for "clickkupToken" from my project for clarity's sake - the fetchClickupObject() function works for lots of other call types in the same project so I know that's not the issue. – jdavis Mar 02 '21 at 15:19
  • OK but I still have the same question where does it get defined. The example you’ve given us is not reproducible because we don’t know where it got defined – Cooper Mar 02 '21 at 15:23
  • Oh I see, on your clickup account go to setting > apps - and there should be an api token at the top – jdavis Mar 02 '21 at 16:04

1 Answers1

10

After some back and forth with the tech team at Clickup, they suggested I try to append status%5B%5D=statusName for each status I wanted to add. The working version looks like this.

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


getTasks() {
    const listId = '****';
    const statusArray = ['Backlog', 'Todo'];
    const statusString = statusArray.map((el) => `&statuses%5B%5D=${el}`).join('');

    const url = `${this.clickupUrl}/list/${listId}/task?archived=false&page=&order_by=&reverse=&subtasks=${statusString}`;
    const params = { url, method: 'GET' };
    const res = this.fetchClickupObject(params);
  }

fetchClickupObject(params: any): Promise<any> {
    const response = fetch(params.url, {
      headers: this.clickupReqBody,
      method: params.method,
    });
    return response;
  }
Igor Kurkov
  • 4,318
  • 2
  • 30
  • 31
jdavis
  • 429
  • 6
  • 16