Request.put doesn't update my tasks

Hello I got a small script that’s supposed to prefix a task with a warning if it’s older than six months.
Everything seems fine, but the put request doesn’t work. It doesn’t throw an error and the json looks fine. What am I missing?

// Send a GET request to the Asana API to retrieve the list of tasks in the project
request.get({
url: https://app.asana.com/api/1.0/projects/${projectId}/tasks,
headers: {
‘Authorization’: Bearer ${accessToken}
}
}, (error, response, body) => {
if (error) {
console.error(‘Error:’, error);
return;
}

// Parse the response body to get the list of tasks
const tasks = JSON.parse(body).data;

// Iterate through the list of tasks
tasks.forEach(task => {
// Check if the task was created more than six months ago
const taskAgeInMonths = moment().diff(moment(task.created_at), ‘months’);
if (taskAgeInMonths > 6) {
// Check if the task title starts with “WARNING”
if (!task.name.startsWith(‘WARNING’)) {
// Use the Asana API to update the task title with “WARNING” as a prefix
const taskId = task.gid;
const updatedTitle = 'WARNING ’ + task.name;
request.put({
url: https://app.asana.com/api/1.0/tasks/${taskId},
headers: {
‘Authorization’: Bearer ${accessToken}
},
json: {
name: updatedTitle
}
}, (error, response, body) => {
if (error) {
console.error(Error updating task ${taskId}:, error);
return;
}

      console.log(`Updated task ${taskId}:`, task.name);
    });
  }
}

});
});

Did you consider using the nodeJS library instead of recoding everything? It would allow you to make sure you have the right syntax.

I believe the problem lies with your json object passed to the server. I don’t think this is what should wrap your data. Try using data instead?

You can also download the Postman library from Asana and look at the format of their call :slight_smile: