Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/12aed0c9b9b6f422a9e755375e2701f2 to your computer and use it in GitHub Desktop.
Save Garconis/12aed0c9b9b6f422a9e755375e2701f2 to your computer and use it in GitHub Desktop.
Asana API + Zapier | find specific subtasks of a parent and then assign them
const res = await fetch('https://app.asana.com/api/1.0/tasks/' + inputData.parentTaskID + '/subtasks', {
headers: {
'Authorization': 'Bearer 1/1234'
}
});
// Sends a JSON response composed of the specified data
const body = await res.json();
// Grabs the "data" content of the response
const data = body.data;
// Specify what we're going to look for within the response
const weLookForThisGoogleCloud = 'Text in this subtask name that you want';
const weLookForThisWPBoom = 'Another subtask name';
const weLookForThisPluginManagement = 'A third subtask name here';
// https://playcode.io/737049/
// https://stackoverflow.com/questions/66177251/extracting-a-particular-project-id-from-asana-task-api-via-node-js-json-output
//var found = body.data.projects.find(project => project.name.includes(weLookForThis)).gid;
const theSubtaskGoogleCloud = data.find(s => s.name.includes(weLookForThisGoogleCloud));
const theSubtaskWPBoom = data.find(s => s.name.includes(weLookForThisWPBoom));
const theSubtaskPluginManagement = data.find(s => s.name.includes(weLookForThisPluginManagement));
// output = { id: data };
// output = { id: projects };
// output = { id: found }
if (theSubtaskGoogleCloud) {
var taskGoogleCloud = theSubtaskGoogleCloud.gid;
let body = {
"data": {
"assignee": "123456" // Paul
}
};
const res = await fetch('https://app.asana.com/api/1.0/tasks/'+taskGoogleCloud, {
method: 'PUT',
headers: {
'Authorization': 'Bearer 1/1234'
},
body: JSON.stringify(body)
});
} else {
var taskGoogleCloud = 'NA';
}
if (theSubtaskWPBoom ) {
var taskWPBoom = theSubtaskWPBoom.gid;
let body = {
"data": {
"assignee": "987654" // Betty
}
};
const res = await fetch('https://app.asana.com/api/1.0/tasks/'+taskWPBoom, {
method: 'PUT',
headers: {
'Authorization': 'Bearer 1/1234'
},
body: JSON.stringify(body)
});
} else {
var taskWPBoom = 'NA';
}
if (theSubtaskPluginManagement ) {
var taskPluginManagement = theSubtaskPluginManagement.gid;
let body = {
"data": {
"assignee": "987654" // Betty
}
};
const res = await fetch('https://app.asana.com/api/1.0/tasks/'+taskPluginManagement, {
method: 'PUT',
headers: {
'Authorization': 'Bearer 1/1234'
},
body: JSON.stringify(body)
});
} else {
var taskPluginManagement = 'NA';
}
output = [{taskGoogleCloud:taskGoogleCloud, taskWPBoom:taskWPBoom, taskPluginManagement:taskPluginManagement}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment