Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created April 28, 2023 17:07
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/59061c6289e6b152aeee74a19517c747 to your computer and use it in GitHub Desktop.
Save Garconis/59061c6289e6b152aeee74a19517c747 to your computer and use it in GitHub Desktop.
Asana API + Zapier | search for a task with criteria and return GID
const res = await fetch('https://app.asana.com/api/1.0/workspaces/9876543/tasks/search?projects.all=1204442834902858&sections.any=1204442834902861,1204442834902862&completed=false&text=' + inputData.foundText + '&opt_fields=gid', {
headers: {
'Authorization': 'Bearer 0/1234567'
}
});
// 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;
// get just the GID (and only the first one if more than one is found)
const theTask = body.data.find(theData => theData.gid);
// output all the data (all the GIDs if multiple, blank if nothing)
// output = { searchoutput: data};
// output the first GID only (or no "searchoutput" at all, if nothing)
// output = { searchoutput: theTask };
// if the search found a GID, output it ... otherwise output NA
if (theTask) {
output = { searchoutput: theTask };
} else {
output = { searchoutput: 'NA' };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment