2019-06-23 03:35:23 -07:00
import {
IExecuteFunctions ,
} from 'n8n-core' ;
2020-09-08 05:00:54 -07:00
2019-06-23 03:35:23 -07:00
import {
IDataObject ,
ILoadOptionsFunctions ,
INodeExecutionData ,
2020-09-08 05:00:54 -07:00
INodePropertyOptions ,
2019-06-23 03:35:23 -07:00
INodeType ,
2020-09-08 05:00:54 -07:00
INodeTypeDescription ,
2019-06-23 03:35:23 -07:00
} from 'n8n-workflow' ;
import {
asanaApiRequest ,
2020-09-08 05:00:54 -07:00
asanaApiRequestAllItems ,
2020-12-25 11:41:48 -08:00
getTaskFields ,
2020-09-16 09:20:27 -07:00
getWorkspaces ,
2019-06-23 03:35:23 -07:00
} from './GenericFunctions' ;
2020-12-22 14:44:31 -08:00
import * as moment from 'moment-timezone' ;
2020-12-27 23:48:57 -08:00
import {
2020-12-25 11:41:48 -08:00
snakeCase ,
} from 'change-case' ;
2019-06-23 03:35:23 -07:00
export class Asana implements INodeType {
description : INodeTypeDescription = {
displayName : 'Asana' ,
name : 'asana' ,
icon : 'file:asana.png' ,
group : [ 'input' ] ,
version : 1 ,
2019-07-12 09:35:35 -07:00
subtitle : '={{$parameter["operation"] + ": " + $parameter["resource"]}}' ,
2020-09-08 05:00:54 -07:00
description : 'Consume Asana REST API' ,
2019-06-23 03:35:23 -07:00
defaults : {
name : 'Asana' ,
2020-09-08 05:00:54 -07:00
color : '#FC636B' ,
2019-06-23 03:35:23 -07:00
} ,
inputs : [ 'main' ] ,
outputs : [ 'main' ] ,
credentials : [
{
name : 'asanaApi' ,
required : true ,
2020-09-16 09:20:27 -07:00
displayOptions : {
show : {
authentication : [
'accessToken' ,
] ,
} ,
} ,
} ,
{
name : 'asanaOAuth2Api' ,
required : true ,
displayOptions : {
show : {
authentication : [
'oAuth2' ,
] ,
} ,
} ,
2020-09-08 05:00:54 -07:00
} ,
2019-06-23 03:35:23 -07:00
] ,
properties : [
2020-09-16 09:20:27 -07:00
{
displayName : 'Authentication' ,
name : 'authentication' ,
type : 'options' ,
options : [
{
name : 'Access Token' ,
value : 'accessToken' ,
} ,
{
name : 'OAuth2' ,
value : 'oAuth2' ,
} ,
] ,
default : 'accessToken' ,
description : 'The resource to operate on.' ,
} ,
2019-07-12 09:35:35 -07:00
{
displayName : 'Resource' ,
name : 'resource' ,
type : 'options' ,
options : [
2020-09-08 05:00:54 -07:00
{
name : 'Project' ,
value : 'project' ,
} ,
2020-12-22 14:44:31 -08:00
{
name : 'Subtask' ,
value : 'subtask' ,
} ,
2019-07-12 09:35:35 -07:00
{
name : 'Task' ,
value : 'task' ,
} ,
2020-09-08 05:00:54 -07:00
{
name : 'Task Comment' ,
value : 'taskComment' ,
} ,
{
name : 'Task Tag' ,
value : 'taskTag' ,
} ,
2021-01-30 09:34:49 -08:00
{
name : 'Task Project' ,
value : 'taskProject' ,
} ,
2019-07-12 09:35:35 -07:00
{
name : 'User' ,
value : 'user' ,
} ,
] ,
default : 'task' ,
description : 'The resource to operate on.' ,
} ,
2020-12-22 14:44:31 -08:00
// ----------------------------------
// subtask
// ----------------------------------
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'subtask' ,
] ,
} ,
} ,
options : [
{
name : 'Create' ,
value : 'create' ,
description : 'Create a subtask' ,
} ,
2020-12-25 11:41:48 -08:00
{
name : 'Get All' ,
value : 'getAll' ,
description : 'Get all substasks' ,
} ,
2020-12-22 14:44:31 -08:00
] ,
default : 'create' ,
description : 'The operation to perform.' ,
} ,
// ----------------------------------
// subtask:create
// ----------------------------------
{
displayName : 'Parent Task ID' ,
name : 'taskId' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'create' ,
] ,
resource : [
'subtask' ,
] ,
} ,
} ,
description : 'The task to operate on.' ,
} ,
{
displayName : 'Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'create' ,
] ,
resource : [
'subtask' ,
] ,
} ,
} ,
description : 'The name of the subtask to create' ,
} ,
{
displayName : 'Additional Fields' ,
name : 'otherProperties' ,
type : 'collection' ,
displayOptions : {
show : {
resource : [
'subtask' ,
] ,
operation : [
'create' ,
] ,
} ,
} ,
default : { } ,
placeholder : 'Add Field' ,
options : [
{
displayName : 'Assignee' ,
name : 'assignee' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getUsers' ,
} ,
default : '' ,
description : 'Set Assignee on the subtask' ,
} ,
{
displayName : 'Assignee Status' ,
name : 'assignee_status' ,
type : 'options' ,
options : [
{
name : 'Inbox' ,
value : 'inbox' ,
} ,
{
name : 'Today' ,
value : 'today' ,
} ,
{
name : 'Upcoming' ,
value : 'upcoming' ,
} ,
{
name : 'Later' ,
value : 'later' ,
} ,
] ,
default : 'inbox' ,
description : 'Set Assignee status on the subtask (requires Assignee)' ,
} ,
{
displayName : 'Completed' ,
name : 'completed' ,
type : 'boolean' ,
default : false ,
description : 'If the subtask should be marked completed.' ,
} ,
{
displayName : 'Due On' ,
name : 'due_on' ,
type : 'dateTime' ,
default : '' ,
description : 'Date on which the time is due.' ,
} ,
{
displayName : 'Liked' ,
name : 'liked' ,
type : 'boolean' ,
default : false ,
description : 'If the task is liked by the authorized user.' ,
} ,
{
displayName : 'Notes' ,
name : 'notes' ,
type : 'string' ,
typeOptions : {
alwaysOpenEditWindow : true ,
rows : 5 ,
} ,
default : '' ,
description : 'The task notes' ,
} ,
{
displayName : 'Workspace' ,
name : 'workspace' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getWorkspaces' ,
} ,
default : '' ,
description : 'The workspace to create the subtask in' ,
} ,
] ,
} ,
2020-12-25 11:41:48 -08:00
// ----------------------------------
// subtask:getAll
// ----------------------------------
{
displayName : 'Parent Task ID' ,
name : 'taskId' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'subtask' ,
] ,
} ,
} ,
description : 'The task to operate on.' ,
} ,
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'subtask' ,
] ,
} ,
} ,
default : false ,
description : 'If all results should be returned or only up to a given limit.' ,
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'subtask' ,
] ,
returnAll : [
false ,
] ,
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 500 ,
} ,
default : 100 ,
description : 'How many results to return.' ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'subtask' ,
] ,
} ,
} ,
default : { } ,
placeholder : 'Add Field' ,
options : [
{
displayName : 'Fields' ,
name : 'opt_fields' ,
type : 'multiOptions' ,
typeOptions : {
loadOptionsMethod : 'getTaskFields' ,
} ,
default : [
'gid' ,
'name' ,
'resource_type' ,
] ,
description : 'Defines fields to return.' ,
} ,
{
displayName : 'Pretty' ,
name : 'opt_pretty' ,
type : 'boolean' ,
default : false ,
description : 'Provides “pretty” output.' ,
} ,
] ,
} ,
2019-07-12 09:35:35 -07:00
// ----------------------------------
// task
// ----------------------------------
2019-06-23 03:35:23 -07:00
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2019-07-12 09:35:35 -07:00
displayOptions : {
show : {
resource : [
'task' ,
] ,
} ,
} ,
2019-06-23 03:35:23 -07:00
options : [
{
2019-07-12 09:35:35 -07:00
name : 'Create' ,
value : 'create' ,
description : 'Create a task' ,
2019-06-23 03:35:23 -07:00
} ,
{
2019-07-12 09:35:35 -07:00
name : 'Delete' ,
value : 'delete' ,
2019-06-23 03:35:23 -07:00
description : 'Delete a task' ,
} ,
{
2019-07-12 09:35:35 -07:00
name : 'Get' ,
value : 'get' ,
2020-09-08 05:00:54 -07:00
description : 'Get a task' ,
2019-06-23 03:35:23 -07:00
} ,
2020-12-22 14:44:31 -08:00
{
name : 'Get All' ,
value : 'getAll' ,
description : 'Get all tasks' ,
} ,
2019-06-23 03:35:23 -07:00
{
2020-09-08 05:00:54 -07:00
name : 'Move' ,
value : 'move' ,
description : 'Move a task' ,
2019-06-23 03:35:23 -07:00
} ,
{
2019-07-12 09:35:35 -07:00
name : 'Search' ,
value : 'search' ,
description : 'Search for tasks' ,
2019-06-23 03:35:23 -07:00
} ,
2020-09-08 05:00:54 -07:00
{
name : 'Update' ,
value : 'update' ,
description : 'Update a task' ,
} ,
2019-06-23 03:35:23 -07:00
] ,
2019-07-12 09:35:35 -07:00
default : 'create' ,
2019-06-23 03:35:23 -07:00
description : 'The operation to perform.' ,
} ,
// ----------------------------------
2019-07-12 09:35:35 -07:00
// task:create
2019-06-23 03:35:23 -07:00
// ----------------------------------
{
displayName : 'Workspace' ,
name : 'workspace' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getWorkspaces' ,
} ,
options : [ ] ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-12 09:35:35 -07:00
'create' ,
] ,
resource : [
'task' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
description : 'The workspace to create the task in' ,
} ,
{
displayName : 'Name' ,
2019-07-12 09:35:35 -07:00
name : 'name' ,
2019-06-23 03:35:23 -07:00
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-12 09:35:35 -07:00
'create' ,
] ,
resource : [
'task' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
description : 'The name of the task to create' ,
} ,
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:delete
2019-06-23 03:35:23 -07:00
// ----------------------------------
{
displayName : 'Task ID' ,
2019-07-12 09:35:35 -07:00
name : 'id' ,
2019-06-23 03:35:23 -07:00
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-12 09:35:35 -07:00
'delete' ,
] ,
resource : [
'task' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
description : 'The ID of the task to delete.' ,
} ,
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:get
2019-06-23 03:35:23 -07:00
// ----------------------------------
{
displayName : 'Task ID' ,
2019-07-12 09:35:35 -07:00
name : 'id' ,
2019-06-23 03:35:23 -07:00
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-12 09:35:35 -07:00
'get' ,
] ,
resource : [
'task' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
description : 'The ID of the task to get the data of.' ,
} ,
2020-12-22 14:44:31 -08:00
// ----------------------------------
// task:getAll
// ----------------------------------
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'task' ,
] ,
} ,
} ,
default : false ,
description : 'If all results should be returned or only up to a given limit.' ,
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'task' ,
] ,
returnAll : [
false ,
] ,
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 500 ,
} ,
default : 100 ,
description : 'How many results to return.' ,
} ,
{
displayName : 'Filters' ,
name : 'filters' ,
type : 'collection' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'task' ,
] ,
} ,
} ,
default : { } ,
description : 'Properties to search for' ,
placeholder : 'Add Filter' ,
options : [
{
displayName : 'Assignee' ,
name : 'assignee' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getUsers' ,
} ,
default : '' ,
description : 'The assignee to filter tasks on. Note: If you specify assignee, you must also specify the workspace to filter on.' ,
} ,
{
displayName : 'Fields' ,
name : 'opt_fields' ,
2020-12-25 11:41:48 -08:00
type : 'multiOptions' ,
typeOptions : {
loadOptionsMethod : 'getTaskFields' ,
} ,
default : [
'gid' ,
'name' ,
'resource_type' ,
] ,
description : 'Defines fields to return.' ,
2020-12-22 14:44:31 -08:00
} ,
{
displayName : 'Pretty' ,
name : 'opt_pretty' ,
type : 'boolean' ,
default : false ,
description : 'Provides “pretty” output.' ,
} ,
{
displayName : 'Project' ,
name : 'project' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getProjects' ,
} ,
default : '' ,
description : 'The project to filter tasks on.' ,
} ,
{
displayName : 'Section' ,
name : 'section' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getSections' ,
} ,
default : '' ,
description : 'The section to filter tasks on.' ,
} ,
{
2020-12-25 11:41:48 -08:00
displayName : 'Workspace' ,
2020-12-22 14:44:31 -08:00
name : 'workspace' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getWorkspaces' ,
} ,
default : '' ,
description : 'The workspace to filter tasks on. Note: If you specify workspace, you must also specify the assignee to filter on.' ,
} ,
{
displayName : 'Completed Since' ,
name : 'completed_since' ,
type : 'dateTime' ,
default : '' ,
description : 'Only return tasks that are either incomplete or that have been completed since this time.' ,
} ,
{
displayName : 'Modified Since' ,
name : 'modified_since' ,
type : 'dateTime' ,
default : '' ,
description : 'Only return tasks that have been modified since the given time.' ,
} ,
] ,
} ,
2019-06-23 03:35:23 -07:00
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:move
// ----------------------------------
{
displayName : 'Task ID' ,
name : 'id' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'move' ,
] ,
resource : [
'task' ,
] ,
} ,
} ,
description : 'The ID of the task to be moved.' ,
} ,
{
displayName : 'Project' ,
name : 'projectId' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getProjects' ,
} ,
options : [ ] ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'move' ,
] ,
resource : [
'task' ,
] ,
} ,
} ,
description : 'Project to show the sections of.' ,
} ,
{
displayName : 'Section' ,
name : 'section' ,
type : 'options' ,
typeOptions : {
loadOptionsDependsOn : [
'projectId' ,
] ,
2020-09-08 05:01:16 -07:00
loadOptionsMethod : 'getSections' ,
2020-09-08 05:00:54 -07:00
} ,
options : [ ] ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'move' ,
] ,
resource : [
'task' ,
] ,
} ,
} ,
description : 'The Section to move the task to' ,
} ,
// ----------------------------------
// task:update
2019-06-23 03:35:23 -07:00
// ----------------------------------
{
displayName : 'Task ID' ,
2019-07-12 09:35:35 -07:00
name : 'id' ,
2019-06-23 03:35:23 -07:00
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-12 09:35:35 -07:00
'update' ,
] ,
resource : [
'task' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
description : 'The ID of the task to update the data of.' ,
} ,
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:search
2019-06-23 03:35:23 -07:00
// ----------------------------------
{
displayName : 'Workspace' ,
name : 'workspace' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getWorkspaces' ,
} ,
options : [ ] ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-12 09:35:35 -07:00
'search' ,
] ,
resource : [
'task' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
2020-09-08 05:00:54 -07:00
description : 'The workspace in which the task is searched' ,
2019-06-23 03:35:23 -07:00
} ,
{
2020-09-08 05:00:54 -07:00
displayName : 'Filters' ,
2019-06-23 03:35:23 -07:00
name : 'searchTaskProperties' ,
type : 'collection' ,
displayOptions : {
show : {
operation : [
2019-07-12 09:35:35 -07:00
'search' ,
] ,
resource : [
'task' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
default : { } ,
description : 'Properties to search for' ,
2020-09-08 05:00:54 -07:00
placeholder : 'Add Filter' ,
2019-06-23 03:35:23 -07:00
options : [
2020-09-08 05:00:54 -07:00
{
displayName : 'Completed' ,
name : 'completed' ,
type : 'boolean' ,
default : false ,
description : 'If the task is marked completed.' ,
} ,
2019-06-23 03:35:23 -07:00
{
displayName : 'Text' ,
name : 'text' ,
type : 'string' ,
typeOptions : {
alwaysOpenEditWindow : true ,
rows : 5 ,
} ,
default : '' ,
description : 'Text to search for in name or notes.' ,
} ,
] ,
} ,
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:create/update
2019-06-23 03:35:23 -07:00
// ----------------------------------
{
2020-09-08 05:00:54 -07:00
displayName : 'Additional Fields' ,
2019-06-23 03:35:23 -07:00
name : 'otherProperties' ,
type : 'collection' ,
displayOptions : {
2019-07-12 09:35:35 -07:00
show : {
resource : [
'task' ,
] ,
2019-06-23 03:35:23 -07:00
operation : [
2019-07-12 09:35:35 -07:00
'create' ,
'update' ,
2019-06-23 03:35:23 -07:00
] ,
} ,
} ,
default : { } ,
2020-09-08 05:00:54 -07:00
placeholder : 'Add Field' ,
2019-06-23 03:35:23 -07:00
options : [
{
2020-09-08 05:00:54 -07:00
displayName : 'Assignee' ,
name : 'assignee' ,
type : 'options' ,
2019-06-23 03:35:23 -07:00
typeOptions : {
2020-09-08 05:00:54 -07:00
loadOptionsMethod : 'getUsers' ,
2019-06-23 03:35:23 -07:00
} ,
default : '' ,
2020-09-08 05:00:54 -07:00
description : 'Set Assignee on the task' ,
} ,
{
displayName : 'Assignee Status' ,
name : 'assignee_status' ,
type : 'options' ,
options : [
{
name : 'Inbox' ,
value : 'inbox' ,
} ,
{
name : 'Today' ,
value : 'today' ,
} ,
{
name : 'Upcoming' ,
value : 'upcoming' ,
} ,
{
name : 'Later' ,
value : 'later' ,
} ,
] ,
default : 'inbox' ,
description : 'Set Assignee status on the task (requires Assignee)' ,
2019-06-23 03:35:23 -07:00
} ,
{
displayName : 'Completed' ,
name : 'completed' ,
type : 'boolean' ,
default : false ,
description : 'If the task should be marked completed.' ,
} ,
{
displayName : 'Due On' ,
name : 'due_on' ,
type : 'dateTime' ,
default : '' ,
description : 'Date on which the time is due.' ,
} ,
2020-09-08 05:00:54 -07:00
{
displayName : 'Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
displayOptions : {
show : {
'/operation' : [
'update' ,
] ,
} ,
} ,
description : 'The new name of the task' ,
} ,
2019-06-23 03:35:23 -07:00
{
displayName : 'Liked' ,
name : 'liked' ,
type : 'boolean' ,
default : false ,
description : 'If the task is liked by the authorized user.' ,
} ,
2020-09-08 05:00:54 -07:00
{
displayName : 'Notes' ,
name : 'notes' ,
type : 'string' ,
typeOptions : {
alwaysOpenEditWindow : true ,
rows : 5 ,
} ,
default : '' ,
description : 'The task notes' ,
} ,
2021-01-30 09:34:49 -08:00
{
displayName : 'Project IDs' ,
name : 'projects' ,
type : 'multiOptions' ,
typeOptions : {
loadOptionsMethod : 'getProjects' ,
} ,
default : [ ] ,
description : 'The project to filter tasks on.' ,
} ,
2019-06-23 03:35:23 -07:00
] ,
} ,
2019-07-12 09:35:35 -07:00
// ----------------------------------
2020-09-08 05:00:54 -07:00
// taskComment
2019-07-12 09:35:35 -07:00
// ----------------------------------
2020-09-08 05:00:54 -07:00
2019-07-12 09:35:35 -07:00
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
2020-09-08 05:00:54 -07:00
'taskComment' ,
2019-07-12 09:35:35 -07:00
] ,
} ,
} ,
options : [
{
2020-09-08 05:00:54 -07:00
name : 'Add' ,
value : 'add' ,
description : 'Add a comment to a task' ,
2019-07-12 09:35:35 -07:00
} ,
{
2020-09-08 05:00:54 -07:00
name : 'Remove' ,
value : 'remove' ,
description : 'Remove a comment from a task' ,
2019-07-12 09:35:35 -07:00
} ,
] ,
2020-09-08 05:00:54 -07:00
default : 'add' ,
2019-07-12 09:35:35 -07:00
description : 'The operation to perform.' ,
} ,
// ----------------------------------
2020-09-08 05:00:54 -07:00
// taskComment:add
2019-07-12 09:35:35 -07:00
// ----------------------------------
2020-09-08 05:00:54 -07:00
2019-07-12 09:35:35 -07:00
{
2020-09-08 05:00:54 -07:00
displayName : 'Task ID' ,
name : 'id' ,
2019-07-12 09:35:35 -07:00
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2020-09-08 05:00:54 -07:00
'add' ,
2019-07-12 09:35:35 -07:00
] ,
resource : [
2020-09-08 05:00:54 -07:00
'taskComment' ,
2019-07-12 09:35:35 -07:00
] ,
} ,
} ,
2020-09-08 05:00:54 -07:00
description : 'The ID of the task to add the comment to' ,
2019-07-12 09:35:35 -07:00
} ,
{
2020-09-08 05:00:54 -07:00
displayName : 'Is Text HTML' ,
name : 'isTextHtml' ,
type : 'boolean' ,
displayOptions : {
show : {
operation : [
'add' ,
] ,
resource : [
'taskComment' ,
] ,
} ,
} ,
default : false ,
description : 'If body is HTML or simple text.' ,
} ,
{
displayName : 'Text' ,
name : 'text' ,
type : 'string' ,
default : '' ,
required : true ,
2019-07-12 09:35:35 -07:00
typeOptions : {
2020-09-08 05:00:54 -07:00
alwaysOpenEditWindow : true ,
2019-07-12 09:35:35 -07:00
} ,
2020-09-08 05:00:54 -07:00
displayOptions : {
show : {
operation : [
'add' ,
] ,
resource : [
'taskComment' ,
] ,
isTextHtml : [
false ,
] ,
} ,
} ,
description : 'The plain text of the comment to add' ,
} ,
{
displayName : 'HTML Text' ,
2020-09-08 05:01:16 -07:00
name : 'text' ,
2020-09-08 05:00:54 -07:00
type : 'string' ,
2019-07-12 09:35:35 -07:00
default : '' ,
required : true ,
2020-09-08 05:00:54 -07:00
typeOptions : {
alwaysOpenEditWindow : true ,
} ,
2019-07-12 09:35:35 -07:00
displayOptions : {
show : {
operation : [
2020-09-08 05:00:54 -07:00
'add' ,
2019-07-12 09:35:35 -07:00
] ,
resource : [
2020-09-08 05:00:54 -07:00
'taskComment' ,
] ,
isTextHtml : [
true ,
2019-07-12 09:35:35 -07:00
] ,
} ,
} ,
2020-09-08 05:00:54 -07:00
description : 'Comment as HTML string. Do not use together with plain text.' ,
} ,
{
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
type : 'collection' ,
displayOptions : {
show : {
operation : [
'add' ,
] ,
resource : [
'taskComment' ,
] ,
} ,
} ,
default : { } ,
description : 'Properties of the task comment' ,
placeholder : 'Add Field' ,
options : [
{
displayName : 'Pinned' ,
name : 'is_pinned' ,
type : 'boolean' ,
default : false ,
description : 'Pin the comment.' ,
} ,
] ,
2019-07-12 09:35:35 -07:00
} ,
2019-06-23 03:35:23 -07:00
2020-09-08 05:00:54 -07:00
// ----------------------------------
// taskComment:remove
// ----------------------------------
2019-06-23 03:35:23 -07:00
2020-09-08 05:00:54 -07:00
{
displayName : 'Comment ID' ,
name : 'id' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'remove' ,
] ,
resource : [
'taskComment' ,
] ,
} ,
} ,
description : 'The ID of the comment to be removed' ,
} ,
2019-06-23 03:35:23 -07:00
2021-01-30 09:34:49 -08:00
// ----------------------------------
// taskProject
// ----------------------------------
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'taskProject' ,
] ,
} ,
} ,
options : [
{
name : 'Add' ,
value : 'add' ,
description : 'Add a task to a project' ,
} ,
{
name : 'Remove' ,
value : 'remove' ,
description : 'Remove a task from a project' ,
} ,
] ,
default : 'add' ,
description : 'The operation to perform.' ,
} ,
// ----------------------------------
// taskProject:add
// ----------------------------------
{
displayName : 'Task ID' ,
name : 'id' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'add' ,
] ,
resource : [
'taskProject' ,
] ,
} ,
} ,
description : 'The ID of the task to add the project to' ,
} ,
{
displayName : 'Project ID' ,
name : 'project' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getProjects' ,
} ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'add' ,
] ,
resource : [
'taskProject' ,
] ,
} ,
} ,
description : 'The project where the task will be added' ,
} ,
{
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
type : 'collection' ,
displayOptions : {
show : {
resource : [
'taskProject' ,
] ,
operation : [
'add' ,
] ,
} ,
} ,
default : { } ,
description : 'Other properties to set' ,
placeholder : 'Add Field' ,
options : [
{
displayName : 'Insert After' ,
name : 'insert_after' ,
type : 'string' ,
default : '' ,
description : 'A task in the project to insert the task after, or null to insert at the beginning of the list.' ,
} ,
{
displayName : 'Insert Before' ,
name : 'insert_before' ,
type : 'string' ,
default : '' ,
description : 'A task in the project to insert the task before, or null to insert at the end of the list.' ,
} ,
{
displayName : 'Section' ,
name : 'section' ,
type : 'string' ,
default : '' ,
description : 'A section in the project to insert the task into. The task will be inserted at the bottom of the section.' ,
} ,
] ,
} ,
// ----------------------------------
// taskProject:remove
// ----------------------------------
{
displayName : 'Task ID' ,
name : 'id' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'remove' ,
] ,
resource : [
'taskProject' ,
] ,
} ,
} ,
description : 'The ID of the task to add the project to' ,
} ,
{
displayName : 'Project ID' ,
name : 'project' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getProjects' ,
} ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'remove' ,
] ,
resource : [
'taskProject' ,
] ,
} ,
} ,
description : 'The project where the task will be removed from' ,
} ,
2020-09-08 05:00:54 -07:00
// ----------------------------------
// taskTag
// ----------------------------------
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'taskTag' ,
] ,
} ,
} ,
options : [
{
name : 'Add' ,
value : 'add' ,
description : 'Add a tag to a task' ,
} ,
{
name : 'Remove' ,
value : 'remove' ,
description : 'Remove a tag from a task' ,
} ,
] ,
default : 'add' ,
description : 'The operation to perform.' ,
} ,
// ----------------------------------
// taskTag:add
// ----------------------------------
{
displayName : 'Task ID' ,
name : 'id' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'add' ,
] ,
resource : [
'taskTag' ,
] ,
} ,
} ,
description : 'The ID of the task to add the tag to' ,
} ,
{
displayName : 'Tags' ,
name : 'tag' ,
type : 'options' ,
typeOptions : {
2020-09-08 05:01:16 -07:00
loadOptionsDependsOn : [
'id' ,
] ,
2020-09-08 05:00:54 -07:00
loadOptionsMethod : 'getTags' ,
} ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'add' ,
] ,
resource : [
'taskTag' ,
] ,
} ,
} ,
description : 'The tag that should be added' ,
} ,
// ----------------------------------
// taskTag:remove
// ----------------------------------
{
displayName : 'Task ID' ,
name : 'id' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'remove' ,
] ,
resource : [
'taskTag' ,
] ,
} ,
} ,
description : 'The ID of the task to add the tag to' ,
} ,
{
displayName : 'Tags' ,
name : 'tag' ,
type : 'options' ,
typeOptions : {
2020-09-08 05:01:16 -07:00
loadOptionsDependsOn : [
'id' ,
] ,
2020-09-08 05:00:54 -07:00
loadOptionsMethod : 'getTags' ,
} ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'remove' ,
] ,
resource : [
'taskTag' ,
] ,
} ,
} ,
description : 'The tag that should be added' ,
} ,
// ----------------------------------
// user
// ----------------------------------
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'user' ,
] ,
} ,
} ,
options : [
{
name : 'Get' ,
value : 'get' ,
description : 'Get a user' ,
} ,
{
name : 'Get All' ,
value : 'getAll' ,
description : 'Get all users' ,
} ,
] ,
default : 'get' ,
description : 'The operation to perform.' ,
} ,
// ----------------------------------
// user:get
// ----------------------------------
{
displayName : 'User ID' ,
name : 'userId' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'get' ,
] ,
resource : [
'user' ,
] ,
} ,
} ,
description : 'An identifier for the user to get data of. Can be one of an<br />email address,the globally unique identifier for the user,<br />or the keyword me to indicate the current user making the request.' ,
} ,
// ----------------------------------
// user:getAll
// ----------------------------------
{
displayName : 'Workspace' ,
name : 'workspace' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getWorkspaces' ,
} ,
options : [ ] ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'user' ,
] ,
} ,
} ,
description : 'The workspace in which to get users.' ,
} ,
// ----------------------------------
// Project
// ----------------------------------
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'project' ,
] ,
} ,
} ,
options : [
{
name : 'Get' ,
value : 'get' ,
description : 'Get a project' ,
} ,
{
name : 'Get All' ,
value : 'getAll' ,
description : 'Get all projects' ,
} ,
] ,
default : 'get' ,
description : 'The operation to perform.' ,
} ,
// ----------------------------------
// project:get
// ----------------------------------
{
displayName : 'Project ID' ,
name : 'id' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'get' ,
] ,
resource : [
'project' ,
] ,
} ,
} ,
} ,
// ----------------------------------
// project:getAll
// ----------------------------------
{
displayName : 'Workspace' ,
name : 'workspace' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getWorkspaces' ,
} ,
options : [ ] ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'project' ,
] ,
} ,
} ,
description : 'The workspace in which to get users.' ,
} ,
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'project' ,
] ,
} ,
} ,
default : false ,
description : 'If all results should be returned or only up to a given limit.' ,
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'project' ,
] ,
returnAll : [
false ,
] ,
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 500 ,
} ,
default : 100 ,
description : 'How many results to return.' ,
} ,
{
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
type : 'collection' ,
displayOptions : {
show : {
resource : [
'project' ,
] ,
operation : [
'getAll' ,
] ,
} ,
} ,
default : { } ,
description : 'Other properties to set' ,
placeholder : 'Add Property' ,
options : [
{
displayName : 'Archived' ,
name : 'archived' ,
type : 'boolean' ,
default : false ,
description : 'Only return projects whose archived field takes on the value of this parameter.' ,
} ,
{
displayName : 'Teams' ,
name : 'team' ,
type : 'options' ,
typeOptions : {
loadOptionsDependsOn : [
'workspace' ,
] ,
loadOptionsMethod : 'getTeams' ,
} ,
default : '' ,
description : 'The new name of the task' ,
} ,
] ,
} ,
] ,
} ;
methods = {
loadOptions : {
// Get all the available workspaces to display them to user so that he can
// select them easily
2020-09-16 09:20:27 -07:00
getWorkspaces ,
2020-09-08 05:00:54 -07:00
// Get all the available projects to display them to user so that they can be
// selected easily
async getProjects ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const endpoint = '/projects' ;
const responseData = await asanaApiRequest . call ( this , 'GET' , endpoint , { } ) ;
if ( responseData . data === undefined ) {
throw new Error ( 'No data got returned' ) ;
}
const returnData : INodePropertyOptions [ ] = [ ] ;
for ( const projectData of responseData . data ) {
if ( projectData . resource_type !== 'project' ) {
// Not sure if for some reason also ever other resources
// get returned but just in case filter them out
continue ;
}
const projectName = projectData . name ;
const projectId = projectData . gid ;
returnData . push ( {
name : projectName ,
value : projectId ,
} ) ;
}
2020-09-08 05:01:16 -07:00
returnData . sort ( ( a , b ) = > {
if ( a . name < b . name ) { return - 1 ; }
if ( a . name > b . name ) { return 1 ; }
return 0 ;
} ) ;
2020-09-08 05:00:54 -07:00
return returnData ;
} ,
// Get all the available sections in a project to display them to user so that they
// can be selected easily
async getSections ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const projectId = this . getNodeParameter ( 'projectId' ) as string ;
const endpoint = ` /projects/ ${ projectId } /sections ` ;
const responseData = await asanaApiRequest . call ( this , 'GET' , endpoint , { } ) ;
if ( responseData . data === undefined ) {
throw new Error ( 'No data got returned' ) ;
}
const returnData : INodePropertyOptions [ ] = [ ] ;
for ( const sectionData of responseData . data ) {
if ( sectionData . resource_type !== 'section' ) {
// Not sure if for some reason also ever other resources
// get returned but just in case filter them out
continue ;
}
returnData . push ( {
name : sectionData.name ,
value : sectionData.gid ,
} ) ;
}
2020-09-08 05:01:16 -07:00
returnData . sort ( ( a , b ) = > {
if ( a . name < b . name ) { return - 1 ; }
if ( a . name > b . name ) { return 1 ; }
return 0 ;
} ) ;
2020-09-08 05:00:54 -07:00
return returnData ;
} ,
// Get all the available teams to display them to user so that he can
// select them easily
async getTeams ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const workspaceId = this . getCurrentNodeParameter ( 'workspace' ) ;
const workspace = await asanaApiRequest . call ( this , 'GET' , ` /workspaces/ ${ workspaceId } ` , { } ) ;
// if the workspace selected it's not an organization then error as they endpoint
// to retrieve the teams from an organization just work with workspaces that are an organization
if ( workspace . is_organization === false ) {
throw Error ( 'To filter by team, the workspace selected has to be an organization' ) ;
}
const endpoint = ` /organizations/ ${ workspaceId } /teams ` ;
const responseData = await asanaApiRequestAllItems . call ( this , 'GET' , endpoint , { } ) ;
const returnData : INodePropertyOptions [ ] = [ ] ;
for ( const teamData of responseData ) {
if ( teamData . resource_type !== 'team' ) {
// Not sure if for some reason also ever other resources
// get returned but just in case filter them out
continue ;
}
returnData . push ( {
name : teamData.name ,
value : teamData.gid ,
} ) ;
}
2020-09-08 05:01:16 -07:00
returnData . sort ( ( a , b ) = > {
if ( a . name < b . name ) { return - 1 ; }
if ( a . name > b . name ) { return 1 ; }
return 0 ;
} ) ;
2020-09-08 05:00:54 -07:00
return returnData ;
} ,
// Get all tags to display them to user so that they can be selected easily
// See: https://developers.asana.com/docs/get-multiple-tags
async getTags ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const endpoint = '/tags' ;
2020-09-08 05:01:16 -07:00
const taskId = this . getNodeParameter ( 'id' ) as string ;
let taskData ;
try {
taskData = await asanaApiRequest . call ( this , 'GET' , ` /tasks/ ${ taskId } ` , { } ) ;
} catch ( e ) {
throw new Error ( ` Could not find task with id " ${ taskId } " so tags could not be loaded. ` ) ;
}
const workspace = taskData . data . workspace . gid ;
const responseData = await asanaApiRequest . call ( this , 'GET' , endpoint , { } , { workspace } ) ;
2020-09-08 05:00:54 -07:00
if ( responseData . data === undefined ) {
throw new Error ( 'No data got returned' ) ;
}
const returnData : INodePropertyOptions [ ] = [ ] ;
for ( const tagData of responseData . data ) {
if ( tagData . resource_type !== 'tag' ) {
// Not sure if for some reason also ever other resources
// get returned but just in case filter them out
continue ;
}
returnData . push ( {
name : tagData.name ,
value : tagData.gid ,
} ) ;
}
2020-09-08 05:01:16 -07:00
returnData . sort ( ( a , b ) = > {
if ( a . name < b . name ) { return - 1 ; }
if ( a . name > b . name ) { return 1 ; }
return 0 ;
} ) ;
2020-09-08 05:00:54 -07:00
return returnData ;
} ,
// Get all users to display them to user so that they can be selected easily
// See: https://developers.asana.com/docs/get-multiple-users
async getUsers ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const endpoint = ` /users ` ;
const responseData = await asanaApiRequest . call ( this , 'GET' , endpoint , { } ) ;
if ( responseData . data === undefined ) {
throw new Error ( 'No data got returned' ) ;
}
const returnData : INodePropertyOptions [ ] = [ ] ;
for ( const userData of responseData . data ) {
if ( userData . resource_type !== 'user' ) {
// Not sure if for some reason also ever other resources
// get returned but just in case filter them out
continue ;
}
returnData . push ( {
name : userData.name ,
value : userData.gid ,
} ) ;
}
2019-06-23 03:35:23 -07:00
return returnData ;
2020-10-22 06:46:03 -07:00
} ,
2020-12-25 11:41:48 -08:00
async getTaskFields ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
for ( const field of getTaskFields ( ) ) {
const value = snakeCase ( field ) ;
returnData . push ( {
name : field ,
value : ( value === '' ) ? '*' : value ,
} ) ;
}
return returnData ;
} ,
2019-06-23 03:35:23 -07:00
} ,
} ;
async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
const items = this . getInputData ( ) ;
const returnData : IDataObject [ ] = [ ] ;
2020-12-22 14:44:31 -08:00
const timezone = this . getTimezone ( ) ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
const resource = this . getNodeParameter ( 'resource' , 0 ) as string ;
2019-06-23 03:35:23 -07:00
const operation = this . getNodeParameter ( 'operation' , 0 ) as string ;
let endpoint = '' ;
let requestMethod = '' ;
let body : IDataObject ;
let qs : IDataObject ;
2020-09-08 05:00:54 -07:00
let responseData ;
2019-06-23 03:35:23 -07:00
for ( let i = 0 ; i < items . length ; i ++ ) {
body = { } ;
qs = { } ;
2020-12-22 14:44:31 -08:00
if ( resource === 'subtask' ) {
if ( operation === 'create' ) {
// ----------------------------------
// subtask:create
// ----------------------------------
const taskId = this . getNodeParameter ( 'taskId' , i ) as string ;
requestMethod = 'POST' ;
endpoint = ` /tasks/ ${ taskId } /subtasks ` ;
body . name = this . getNodeParameter ( 'name' , i ) as string ;
const otherProperties = this . getNodeParameter ( 'otherProperties' , i ) as IDataObject ;
Object . assign ( body , otherProperties ) ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
}
2020-12-25 11:41:48 -08:00
if ( operation === 'getAll' ) {
// ----------------------------------
// subtask:getAll
// ----------------------------------
const taskId = this . getNodeParameter ( 'taskId' , i ) as string ;
const returnAll = this . getNodeParameter ( 'returnAll' , i ) as boolean ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
requestMethod = 'GET' ;
endpoint = ` /tasks/ ${ taskId } /subtasks ` ;
Object . assign ( qs , options ) ;
2020-12-27 23:48:57 -08:00
2020-12-25 11:41:48 -08:00
if ( qs . opt_fields ) {
const fields = qs . opt_fields as string [ ] ;
if ( fields . includes ( '*' ) ) {
qs . opt_fields = getTaskFields ( ) . map ( ( e ) = > snakeCase ( e ) ) . join ( ',' ) ;
} else {
qs . opt_fields = ( qs . opt_fields as string [ ] ) . join ( ',' ) ;
}
}
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
if ( returnAll === false ) {
const limit = this . getNodeParameter ( 'limit' , i ) as boolean ;
responseData = responseData . splice ( 0 , limit ) ;
}
}
2020-12-22 14:44:31 -08:00
}
2019-07-12 09:35:35 -07:00
if ( resource === 'task' ) {
if ( operation === 'create' ) {
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:create
2019-07-12 09:35:35 -07:00
// ----------------------------------
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
requestMethod = 'POST' ;
2020-09-08 05:00:54 -07:00
endpoint = '/tasks' ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
body . name = this . getNodeParameter ( 'name' , i ) as string ;
// body.notes = this.getNodeParameter('taskNotes', 0) as string;
body . workspace = this . getNodeParameter ( 'workspace' , i ) as string ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
const otherProperties = this . getNodeParameter ( 'otherProperties' , i ) as IDataObject ;
Object . assign ( body , otherProperties ) ;
2019-06-23 03:35:23 -07:00
2020-09-08 05:00:54 -07:00
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
2019-07-12 09:35:35 -07:00
} else if ( operation === 'delete' ) {
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:delete
2019-07-12 09:35:35 -07:00
// ----------------------------------
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
requestMethod = 'DELETE' ;
2020-09-08 05:00:54 -07:00
endpoint = '/tasks/' + this . getNodeParameter ( 'id' , i ) as string ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
} else if ( operation === 'get' ) {
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:get
2019-07-12 09:35:35 -07:00
// ----------------------------------
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
requestMethod = 'GET' ;
2020-09-08 05:00:54 -07:00
endpoint = '/tasks/' + this . getNodeParameter ( 'id' , i ) as string ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
2020-12-27 23:48:57 -08:00
2020-12-22 14:44:31 -08:00
} else if ( operation === 'getAll' ) {
2020-12-27 23:48:57 -08:00
// ----------------------------------
// task:getAll
// ----------------------------------
2020-12-25 11:41:48 -08:00
2020-12-27 23:48:57 -08:00
const filters = this . getNodeParameter ( 'filters' , i ) as IDataObject ;
const returnAll = this . getNodeParameter ( 'returnAll' , i ) as boolean ;
2020-12-22 14:44:31 -08:00
2020-12-27 23:48:57 -08:00
requestMethod = 'GET' ;
endpoint = ` /tasks ` ;
Object . assign ( qs , filters ) ;
if ( qs . opt_fields ) {
const fields = qs . opt_fields as string [ ] ;
if ( fields . includes ( '*' ) ) {
qs . opt_fields = getTaskFields ( ) . map ( ( e ) = > snakeCase ( e ) ) . join ( ',' ) ;
2020-12-22 14:44:31 -08:00
} else {
2020-12-27 23:48:57 -08:00
qs . opt_fields = ( qs . opt_fields as string [ ] ) . join ( ',' ) ;
2020-12-22 14:44:31 -08:00
}
2020-12-27 23:48:57 -08:00
}
if ( qs . modified_since ) {
qs . modified_since = moment . tz ( qs . modified_since as string , timezone ) . format ( ) ;
}
if ( qs . completed_since ) {
qs . completed_since = moment . tz ( qs . completed_since as string , timezone ) . format ( ) ;
}
if ( returnAll ) {
responseData = await asanaApiRequestAllItems . call ( this , requestMethod , endpoint , body , qs ) ;
} else {
qs . limit = this . getNodeParameter ( 'limit' , i ) as boolean ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
}
2020-09-08 05:00:54 -07:00
} else if ( operation === 'move' ) {
// ----------------------------------
// task:move
// ----------------------------------
const sectionId = this . getNodeParameter ( 'section' , i ) as string ;
requestMethod = 'POST' ;
endpoint = ` /sections/ ${ sectionId } /addTask ` ;
body . task = this . getNodeParameter ( 'id' , i ) as string ;
Object . assign ( body ) ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = { success : true } ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
} else if ( operation === 'update' ) {
// ----------------------------------
2020-09-08 05:00:54 -07:00
// task:update
2019-07-12 09:35:35 -07:00
// ----------------------------------
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
requestMethod = 'PUT' ;
2020-09-08 05:00:54 -07:00
endpoint = '/tasks/' + this . getNodeParameter ( 'id' , i ) as string ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
const otherProperties = this . getNodeParameter ( 'otherProperties' , i ) as IDataObject ;
Object . assign ( body , otherProperties ) ;
2019-06-23 03:35:23 -07:00
2020-09-08 05:00:54 -07:00
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
2019-07-12 09:35:35 -07:00
} else if ( operation === 'search' ) {
// ----------------------------------
2020-09-08 05:00:54 -07:00
// tasksearch
2019-07-12 09:35:35 -07:00
// ----------------------------------
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
const workspaceId = this . getNodeParameter ( 'workspace' , i ) as string ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
requestMethod = 'GET' ;
2020-09-08 05:00:54 -07:00
endpoint = ` /workspaces/ ${ workspaceId } /tasks/search ` ;
2019-07-12 09:35:35 -07:00
const searchTaskProperties = this . getNodeParameter ( 'searchTaskProperties' , i ) as IDataObject ;
Object . assign ( qs , searchTaskProperties ) ;
2020-09-08 05:00:54 -07:00
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
}
}
if ( resource === 'taskComment' ) {
if ( operation === 'add' ) {
// ----------------------------------
// taskComment:add
// ----------------------------------
const taskId = this . getNodeParameter ( 'id' , i ) as string ;
const isTextHtml = this . getNodeParameter ( 'isTextHtml' , i ) as boolean ;
if ( ! isTextHtml ) {
body . text = this . getNodeParameter ( 'text' , i ) as string ;
} else {
2020-09-08 05:01:16 -07:00
body . html_text = this . getNodeParameter ( 'text' , i ) as string ;
2020-09-08 05:00:54 -07:00
}
requestMethod = 'POST' ;
endpoint = ` /tasks/ ${ taskId } /stories ` ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
Object . assign ( body , additionalFields ) ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
}
if ( operation === 'remove' ) {
// ----------------------------------
// taskComment:remove
// ----------------------------------
const commentId = this . getNodeParameter ( 'id' , i ) as string ;
requestMethod = 'DELETE' ;
endpoint = ` /stories/ ${ commentId } ` ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = { success : true } ;
}
}
if ( resource === 'taskTag' ) {
if ( operation === 'add' ) {
// ----------------------------------
// taskTag:add
// ----------------------------------
const taskId = this . getNodeParameter ( 'id' , i ) as string ;
requestMethod = 'POST' ;
endpoint = ` /tasks/ ${ taskId } /addTag ` ;
body . tag = this . getNodeParameter ( 'tag' , i ) as string ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = { success : true } ;
2019-07-12 09:35:35 -07:00
}
2020-09-08 05:00:54 -07:00
if ( operation === 'remove' ) {
// ----------------------------------
// taskTag:remove
// ----------------------------------
const taskId = this . getNodeParameter ( 'id' , i ) as string ;
requestMethod = 'POST' ;
endpoint = ` /tasks/ ${ taskId } /removeTag ` ;
body . tag = this . getNodeParameter ( 'tag' , i ) as string ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = { success : true } ;
}
}
2021-01-30 09:34:49 -08:00
if ( resource === 'taskProject' ) {
if ( operation === 'add' ) {
// ----------------------------------
// taskProject:add
// ----------------------------------
const taskId = this . getNodeParameter ( 'id' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
requestMethod = 'POST' ;
endpoint = ` /tasks/ ${ taskId } /addProject ` ;
body . project = this . getNodeParameter ( 'project' , i ) as string ;
Object . assign ( body , additionalFields ) ;
2020-09-08 05:00:54 -07:00
2021-01-30 09:34:49 -08:00
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = { success : true } ;
}
if ( operation === 'remove' ) {
// ----------------------------------
// taskProject:remove
// ----------------------------------
const taskId = this . getNodeParameter ( 'id' , i ) as string ;
requestMethod = 'POST' ;
endpoint = ` /tasks/ ${ taskId } /removeProject ` ;
body . project = this . getNodeParameter ( 'project' , i ) as string ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = { success : true } ;
}
}
2020-09-08 05:00:54 -07:00
if ( resource === 'user' ) {
2019-07-12 09:35:35 -07:00
if ( operation === 'get' ) {
// ----------------------------------
// get
// ----------------------------------
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
const userId = this . getNodeParameter ( 'userId' , i ) as string ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
requestMethod = 'GET' ;
2020-09-08 05:00:54 -07:00
endpoint = ` /users/ ${ userId } ` ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
2019-06-23 03:35:23 -07:00
2019-07-12 09:35:35 -07:00
} else if ( operation === 'getAll' ) {
// ----------------------------------
// getAll
// ----------------------------------
const workspaceId = this . getNodeParameter ( 'workspace' , i ) as string ;
requestMethod = 'GET' ;
2020-09-08 05:00:54 -07:00
endpoint = ` /workspaces/ ${ workspaceId } /users ` ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
2019-07-12 09:35:35 -07:00
}
2019-06-23 03:35:23 -07:00
}
2020-09-08 05:00:54 -07:00
if ( resource === 'project' ) {
if ( operation === 'get' ) {
// ----------------------------------
// project:get
// ----------------------------------
const projectId = this . getNodeParameter ( 'id' , i ) as string ;
requestMethod = 'GET' ;
endpoint = ` /projects/ ${ projectId } ` ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
}
if ( operation === 'getAll' ) {
2020-09-08 05:01:16 -07:00
// ----------------------------------
// project:getAll
// ----------------------------------
2020-09-08 05:00:54 -07:00
const workspaceId = this . getNodeParameter ( 'workspace' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const returnAll = this . getNodeParameter ( 'returnAll' , i ) as boolean ;
requestMethod = 'GET' ;
endpoint = ` /projects ` ;
2019-06-23 03:35:23 -07:00
2020-09-08 05:00:54 -07:00
if ( additionalFields . team ) {
qs . team = additionalFields . team ;
} else {
qs . workspace = workspaceId ;
}
if ( additionalFields . archived ) {
qs . archived = additionalFields . archived as boolean ;
}
if ( returnAll ) {
responseData = await asanaApiRequestAllItems . call ( this , requestMethod , endpoint , body , qs ) ;
} else {
qs . limit = this . getNodeParameter ( 'limit' , i ) as boolean ;
responseData = await asanaApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
responseData = responseData . data ;
}
}
}
if ( Array . isArray ( responseData ) ) {
returnData . push . apply ( returnData , responseData as IDataObject [ ] ) ;
} else {
returnData . push ( responseData ) ;
}
2019-06-23 03:35:23 -07:00
}
return [ this . helpers . returnJsonArray ( returnData ) ] ;
}
}