Created
February 25, 2022 07:28
-
-
Save raymondctc/63755a57b17af51a0bebcaee17fbbd9e to your computer and use it in GitHub Desktop.
Batch update ClickUp tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fetch from "node-fetch"; | |
const tasks = { | |
"tasks": {} | |
} | |
const TOKEN = "" | |
const excludedIndex = [0, 1, 4, 5, 6, 7, 8, 9, 10, 23, 24] | |
async function updateTasks() { | |
for (var i = 0; i < tasks.tasks.length; i++) { | |
const item = tasks.tasks[i] | |
console.log(i + ". Task: " + item.id + " " + item.name + " item.assignee=" + item.assignees) | |
if (excludedIndex.indexOf(i) == -1) { | |
const updatedAssignee = await updateTask(item.id) | |
console.log(updatedAssignee) | |
const addBuildNumber = await createTaskComment(item.id, "Build 25585") | |
console.log(addBuildNumber) | |
} | |
} | |
} | |
async function createTaskComment(taskId, commentText) { | |
const endpoint = "https://api.clickup.com/api/v2/task/" + taskId + "/comment" | |
console.log(endpoint) | |
const response = await fetch(endpoint, { | |
method: 'POST', | |
headers: { | |
"Authorization": TOKEN, | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify({ | |
"comment_text": commentText | |
}) | |
}) | |
const result = await response.json() | |
return result | |
} | |
async function updateTask(taskId) { | |
const response = await fetch("https://api.clickup.com/api/v2/task/" + taskId, { | |
method: 'PUT', | |
headers: { | |
"Authorization": TOKEN, | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify({ | |
"assignees": { | |
"add": [37577187], | |
"rem": [7812683] | |
} | |
}) | |
}) | |
const result = await response.json() | |
return result | |
} | |
updateTasks().then(result => { | |
console.log(result) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment