How do I update the user who completed a task with the API
Summary of query: We have an API script to complete a task once a Teamwork Desk ticket is closed or solved. The user who closes the ticket needs to be added as the user who completed the task. Right now, the API user will is set as the task completer.
Aim: Set another user as the task completer based on your process
Endpoint: https://{yourSiteName}.teamwork.com/tasks/{taskId}/properties.json
This is expected behaviour when the complete task endpoint is being used. Once the task is completed you can use the change task properties endpoint (undocumented) to edit the following information on a task.
Task creator (by passing in UserId)
User who completed that task (by passing in UserId)
Alter the completed on date (by passing in the new date)
Example of request below written in JavaScript. The update tasks properties example request and many more can be found on our Teamwork.com request examples repo on GitHub.
Edit task properties
const myHeaders = new Headers();
const userName = "email address or API KEY here";
const password = "password";
const siteName = "yourSiteName"
const taskId = "taskIdHere"
const creatorId = "userIdHere"
const completerId = "userIdHere"
const completedOn = "completedOnHere"//yyyyMMddhhmmss
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic "+btoa(userName+":"+password));
const raw = JSON.stringify({
"todo-item": {
"creator-id": creatorId,
"completer-id": completerId,
"completed-on": completedOn
},
"allow-update": true
});
const requestOptions = {
method: "PUT",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://"+siteName+".teamwork.com/tasks/"+taskId+"/properties.json", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
If you have a similar query or any other feedback please contact api@teamwork.com