Last active
June 17, 2021 12:52
-
-
Save ikbelkirasan/681e26f17f5a2492ea6833e957fff379 to your computer and use it in GitHub Desktop.
Duplicate project in Asana via Zapier Code step
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
const { projectId, teamId, newProjectName, accessToken } = inputData; | |
const payload = { | |
data: { | |
name: newProjectName, | |
team: teamId, | |
include: [ | |
"members", | |
"notes", | |
"task_notes", | |
"task_subtasks", | |
"task_attachments", | |
"task_dependencies", | |
"task_followers", | |
], | |
}, | |
}; | |
const response = await fetch( | |
`https://app.asana.com/api/1.0/projects/${projectId}/duplicate`, | |
{ | |
method: "POST", | |
body: JSON.stringify(payload), | |
headers: { | |
authorization: `Bearer ${accessToken}`, | |
}, | |
} | |
); | |
const data = await response.json(); | |
if (!response.ok) { | |
let errorMessage = `[${response.status}] `; | |
errorMessage += data.errors | |
.map((error) => [error.message, error.help].filter(Boolean).join(" ")) | |
.join("\n"); | |
throw new Error(errorMessage); | |
} | |
return { | |
data, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment