Created
April 28, 2023 17:07
-
-
Save Garconis/59061c6289e6b152aeee74a19517c747 to your computer and use it in GitHub Desktop.
Asana API + Zapier | search for a task with criteria and return GID
This file contains hidden or 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
const res = await fetch('https://app.asana.com/api/1.0/workspaces/9876543/tasks/search?projects.all=1204442834902858§ions.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