Last active
May 17, 2021 20:48
-
-
Save Garconis/37ef584d3dff081b2ba21a1b26a8ac80 to your computer and use it in GitHub Desktop.
Asana | Create new Asana task via API within Zapier
This file contains 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
// this is wrapped in an `async` function | |
// you can use await throughout the function | |
// get personName | |
var personName = inputData.personName; | |
// get dateStart | |
var dateStart = inputData.dateStart; | |
// get dateEnd | |
var dateEnd = inputData.dateEnd; | |
// get dateDuration | |
var dateDuration = inputData.dateDuration; | |
// get taskURL from the custom fields above | |
var theURL = inputData.eventLink; | |
// encode the URL | |
var theEventLinkFinal = encodeURI(theURL); | |
// get dateStartPretty | |
var dateStartPretty = inputData.dateStartPretty; | |
// get dateEndPretty | |
var dateEndPretty = inputData.dateEndPretty; | |
// get projectSection | |
var projectSection = inputData.projectSection; | |
// sets custom dropdown field of Team Member to value of OFF | |
// sets the start date and end date | |
// sets the task Name based on person chosen in Google Form | |
// sets task description (notes) with date range, number of days, and link to Google Calendar event | |
// sets Asana project to "Prod Timelne" and section of the person chosen in the Google Form | |
// adds FS Admin and Kelsey as followers on the task | |
let body = { | |
"data": { | |
"custom_fields": { | |
"123456789": "88661122" | |
}, | |
"start_on": dateStart, | |
"due_on": dateEnd, | |
"name": personName + " Off", | |
"notes": "Date range: " + dateStartPretty + " – " + dateEndPretty + "\n\nTotal number of days: " + dateDuration + "\n\nCalendar link: " + theEventLinkFinal, | |
"memberships": [ | |
{ | |
"project": "981984984798", | |
"section": projectSection | |
}, | |
{ | |
"project": "189987654", | |
"section": "456456456" | |
} | |
], | |
"followers": [ | |
"62871687168", | |
"6817683716874126" | |
], | |
"workspace": "74189675286" | |
} | |
}; | |
// create the task based on the body and data | |
const res = await fetch('https://app.asana.com/api/1.0/tasks', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
'Accept': 'application/json', | |
'Authorization': 'Bearer 0/1789sdfh178s9hdf8179sdfhsdh9f178' | |
}, | |
body: JSON.stringify(body) | |
}); | |
const data = await res.json(); | |
output = { | |
data: data | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment