2019-06-23 12:21:44 -07:00
import {
IExecuteFunctions ,
} from 'n8n-core' ;
import {
IDataObject ,
INodeTypeDescription ,
INodeExecutionData ,
INodeType ,
} from 'n8n-workflow' ;
import {
pipedriveApiRequest ,
pipedriveApiRequestAllItems ,
} from './GenericFunctions' ;
2019-07-10 01:16:48 -07:00
interface CustomProperty {
name : string ;
value : string ;
}
/ * *
* Add the additional fields to the body
*
* @param { IDataObject } body The body object to add fields to
* @param { IDataObject } additionalFields The fields to add
* /
function addAdditionalFields ( body : IDataObject , additionalFields : IDataObject ) {
for ( const key of Object . keys ( additionalFields ) ) {
if ( key === 'customProperties' && ( additionalFields . customProperties as IDataObject ) . property !== undefined ) {
for ( const customProperty of ( additionalFields . customProperties as IDataObject ) ! . property ! as CustomProperty [ ] ) {
body [ customProperty . name ] = customProperty . value ;
}
} else {
body [ key ] = additionalFields [ key ] ;
}
}
}
2019-06-23 12:21:44 -07:00
export class Pipedrive implements INodeType {
description : INodeTypeDescription = {
displayName : 'Pipedrive' ,
name : 'pipedrive' ,
icon : 'file:pipedrive.png' ,
group : [ 'transform' ] ,
version : 1 ,
2019-07-14 09:55:04 -07:00
subtitle : '={{$parameter["operation"] + ": " + $parameter["resource"]}}' ,
2019-06-23 22:24:47 -07:00
description : 'Create and edit data in Pipedrive' ,
2019-06-23 12:21:44 -07:00
defaults : {
name : 'Pipedrive' ,
color : '#227722' ,
} ,
inputs : [ 'main' ] ,
outputs : [ 'main' ] ,
credentials : [
{
name : 'pipedriveApi' ,
required : true ,
}
] ,
properties : [
{
2019-07-14 08:57:08 -07:00
displayName : 'Resource' ,
name : 'resource' ,
2019-06-23 12:21:44 -07:00
type : 'options' ,
options : [
{
2019-07-14 08:57:08 -07:00
name : 'Activity' ,
value : 'activity' ,
} ,
{
name : 'Deal' ,
value : 'deal' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Organization' ,
value : 'organization' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-10 01:16:48 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Person' ,
value : 'person' ,
} ,
{
name : 'Product' ,
value : 'product' ,
} ,
] ,
default : 'deal' ,
description : 'The resource to operate on.' ,
} ,
// ----------------------------------
// operations
// ----------------------------------
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'activity' ,
] ,
2019-07-10 01:16:48 -07:00
} ,
2019-07-14 08:57:08 -07:00
} ,
options : [
2019-06-23 12:21:44 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Create' ,
value : 'create' ,
description : 'Create an activity' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Delete' ,
value : 'delete' ,
2019-06-23 12:21:44 -07:00
description : 'Delete an activity' ,
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Get' ,
value : 'get' ,
description : 'Get data of an activity' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-14 08:57:08 -07:00
// TODO: Currently missing
// {
// name: 'Get All',
// value: 'getAll',
// description: 'Get data of all activities',
// },
2019-07-10 01:16:48 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Update' ,
value : 'update' ,
description : 'Update an activity' ,
} ,
] ,
default : 'create' ,
description : 'The operation to perform.' ,
} ,
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'deal' ,
] ,
2019-07-10 01:16:48 -07:00
} ,
2019-07-14 08:57:08 -07:00
} ,
options : [
2019-06-23 12:21:44 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Create' ,
value : 'create' ,
description : 'Create a deal' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Delete' ,
value : 'delete' ,
description : 'Delete a deal' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Get' ,
value : 'get' ,
2019-06-23 12:21:44 -07:00
description : 'Get data of a deal' ,
} ,
2019-07-14 08:57:08 -07:00
// TODO: Currently missing
// {
// name: 'Get All',
// value: 'getAll',
// description: 'Get data of all deals',
// },
2019-06-23 12:21:44 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Update' ,
value : 'update' ,
description : 'Update a deal' ,
} ,
] ,
default : 'create' ,
description : 'The operation to perform.' ,
} ,
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'organization' ,
] ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-14 08:57:08 -07:00
} ,
options : [
2019-06-23 12:21:44 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Create' ,
value : 'create' ,
description : 'Create an organization' ,
} ,
{
name : 'Delete' ,
value : 'delete' ,
description : 'Delete anorganization' ,
} ,
{
name : 'Get' ,
value : 'get' ,
description : 'Get data of an organization' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-09 23:40:59 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Get All' ,
value : 'getAll' ,
2019-07-09 23:40:59 -07:00
description : 'Get data of all organizations' ,
} ,
2019-07-14 08:57:08 -07:00
// TODO: Currently missing
// {
// name: 'Update',
// value: 'update',
// description: 'Update an organization',
// },
] ,
default : 'create' ,
description : 'The operation to perform.' ,
} ,
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'person' ,
] ,
} ,
} ,
options : [
2019-07-09 23:40:59 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Create' ,
value : 'create' ,
description : 'Create a person' ,
2019-07-09 23:40:59 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Delete' ,
value : 'delete' ,
description : 'Delete a person' ,
2019-07-09 23:40:59 -07:00
} ,
2019-06-23 12:21:44 -07:00
{
2019-07-14 08:57:08 -07:00
name : 'Get' ,
value : 'get' ,
description : 'Get data of a person' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Get All' ,
value : 'getAll' ,
description : 'Get data of all persons' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Update' ,
value : 'update' ,
2019-06-23 12:21:44 -07:00
description : 'Update a person' ,
} ,
] ,
2019-07-14 08:57:08 -07:00
default : 'create' ,
description : 'The operation to perform.' ,
} ,
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
displayOptions : {
show : {
resource : [
'product' ,
] ,
} ,
} ,
options : [
{
name : 'Get All' ,
value : 'getAll' ,
description : 'Get data of all products' ,
} ,
] ,
default : 'getAll' ,
2019-06-23 12:21:44 -07:00
description : 'The operation to perform.' ,
} ,
2019-07-14 08:57:08 -07:00
2019-06-23 12:21:44 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// Activity
// ----------------------------------
// ----------------------------------
// activity:create
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
displayName : 'Subject' ,
name : 'subject' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'activity' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
description : 'The subject of the activity to create' ,
} ,
{
displayName : 'Done' ,
name : 'done' ,
type : 'options' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'activity' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
options : [
{
name : 'Not done' ,
value : '0' ,
} ,
{
name : 'Done' ,
value : '1' ,
} ,
] ,
default : '0' ,
description : 'Whether the activity is done or not.' ,
} ,
{
displayName : 'Type' ,
name : 'type' ,
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'activity' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
placeholder : 'call' ,
description : 'Type of the activity like "call", "meeting", ...' ,
} ,
{
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
type : 'collection' ,
placeholder : 'Add Field' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'activity' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : { } ,
options : [
{
displayName : 'Deal ID' ,
name : 'deal_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the deal this activity will be associated with' ,
} ,
{
displayName : 'Note' ,
name : 'note' ,
type : 'string' ,
typeOptions : {
alwaysOpenEditWindow : true ,
rows : 5 ,
} ,
default : '' ,
description : 'Note of the activity (HTML format)' ,
} ,
{
displayName : 'Organization ID' ,
name : 'org_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the organization this activity will be associated with' ,
} ,
{
displayName : 'Person ID' ,
name : 'person_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the person this activity will be associated with' ,
} ,
{
displayName : 'User ID' ,
name : 'user_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the user whom the activity will be assigned to. If omitted, the activity will be assigned to the authorized user.' ,
} ,
2019-07-10 01:16:48 -07:00
{
displayName : 'Custom Properties' ,
name : 'customProperties' ,
placeholder : 'Add Custom Property' ,
description : 'Adds a custom property to set also values which have not been predefined.' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
} ,
default : { } ,
options : [
{
name : 'property' ,
displayName : 'Property' ,
values : [
{
displayName : 'Property Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'Name of the property to set.' ,
} ,
{
displayName : 'Property Value' ,
name : 'value' ,
type : 'string' ,
default : '' ,
description : 'Value of the property to set.' ,
} ,
]
} ,
] ,
} ,
2019-06-23 12:21:44 -07:00
] ,
} ,
2019-07-14 08:57:08 -07:00
// ----------------------------------
// activity:delete
// ----------------------------------
{
displayName : 'Activity ID' ,
name : 'activityId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'delete' ,
] ,
resource : [
'activity' ,
] ,
} ,
} ,
default : 0 ,
required : true ,
description : 'ID of the activity to delete.' ,
} ,
2019-06-23 12:21:44 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// activity:get
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
2019-07-14 08:57:08 -07:00
displayName : 'Activity ID' ,
name : 'activityId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'get'
] ,
resource : [
'activity' ,
] ,
} ,
} ,
default : 0 ,
2019-06-23 12:21:44 -07:00
required : true ,
2019-07-14 08:57:08 -07:00
description : 'ID of the activity to get.' ,
} ,
// ----------------------------------
// activity:update
// ----------------------------------
{
displayName : 'Activity ID' ,
name : 'activityId' ,
type : 'number' ,
2019-06-23 12:21:44 -07:00
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'update'
] ,
resource : [
'activity' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
2019-07-14 08:57:08 -07:00
default : 0 ,
required : true ,
description : 'ID of the activity to update.' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Update Fields' ,
name : 'updateFields' ,
2019-06-23 12:21:44 -07:00
type : 'collection' ,
placeholder : 'Add Field' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'update'
] ,
resource : [
'activity' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : { } ,
options : [
{
2019-07-14 08:57:08 -07:00
displayName : 'Deal ID' ,
name : 'deal_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the deal this activity will be associated with' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Done' ,
name : 'done' ,
type : 'options' ,
options : [
{
name : 'Not done' ,
value : '0' ,
} ,
{
name : 'Done' ,
value : '1' ,
} ,
] ,
default : '0' ,
description : 'Whether the activity is done or not.' ,
} ,
{
displayName : 'Note' ,
name : 'note' ,
2019-06-23 12:21:44 -07:00
type : 'string' ,
2019-07-14 08:57:08 -07:00
typeOptions : {
alwaysOpenEditWindow : true ,
rows : 5 ,
} ,
2019-06-23 12:21:44 -07:00
default : '' ,
2019-07-14 08:57:08 -07:00
description : 'Note of the activity (HTML format)' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'Organization ID' ,
name : 'org_id' ,
type : 'number' ,
default : 0 ,
2019-07-14 08:57:08 -07:00
description : 'ID of the organization this activity will be associated with' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'Person ID' ,
name : 'person_id' ,
type : 'number' ,
default : 0 ,
2019-07-14 08:57:08 -07:00
description : 'ID of the person this activity will be associated with' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Subject' ,
name : 'subject' ,
type : 'string' ,
default : '' ,
description : 'The subject of the activity' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Type' ,
name : 'type' ,
type : 'string' ,
default : '' ,
placeholder : 'call' ,
description : 'Type of the activity like "call", "meeting", ...' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'User ID' ,
name : 'user_id' ,
type : 'number' ,
default : 0 ,
2019-07-14 08:57:08 -07:00
description : 'ID of the user whom the activity will be assigned to. If omitted, the activity will be assigned to the authorized user.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-10 01:16:48 -07:00
{
displayName : 'Custom Properties' ,
name : 'customProperties' ,
placeholder : 'Add Custom Property' ,
description : 'Adds a custom property to set also values which have not been predefined.' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
} ,
default : { } ,
options : [
{
name : 'property' ,
displayName : 'Property' ,
values : [
{
displayName : 'Property Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'Name of the property to set.' ,
} ,
{
displayName : 'Property Value' ,
name : 'value' ,
type : 'string' ,
default : '' ,
description : 'Value of the property to set.' ,
} ,
]
} ,
] ,
} ,
] ,
} ,
2019-07-14 08:57:08 -07:00
2019-07-10 01:16:48 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// deal
2019-07-10 01:16:48 -07:00
// ----------------------------------
2019-06-23 12:21:44 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// deal:create
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
2019-07-14 08:57:08 -07:00
displayName : 'Title' ,
name : 'title' ,
2019-06-23 12:21:44 -07:00
type : 'string' ,
default : '' ,
required : true ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'deal' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
2019-07-14 08:57:08 -07:00
description : 'The title of the deal to create' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
type : 'collection' ,
placeholder : 'Add Field' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'deal' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : { } ,
options : [
{
2019-07-14 08:57:08 -07:00
displayName : 'Currency' ,
name : 'currency' ,
type : 'string' ,
default : 'USD' ,
description : 'Currency of the deal. Accepts a 3-character currency code. Like EUR, USD, ...' ,
} ,
{
displayName : 'Lost Reason' ,
name : 'lost_reason' ,
2019-06-23 12:21:44 -07:00
type : 'string' ,
default : '' ,
2019-07-14 08:57:08 -07:00
description : 'Reason why the deal was lost.' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'Organization ID' ,
name : 'org_id' ,
type : 'number' ,
default : 0 ,
2019-07-14 08:57:08 -07:00
description : 'ID of the organization this deal will be associated with.' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Person ID' ,
name : 'person_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the person this deal will be associated with.' ,
} ,
{
displayName : 'Probability' ,
name : 'probability' ,
type : 'number' ,
2019-06-23 12:21:44 -07:00
typeOptions : {
2019-07-14 08:57:08 -07:00
minValue : 0 ,
maxValue : 100 ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-14 08:57:08 -07:00
default : 0 ,
description : 'Deal success probability percentage.' ,
} ,
{
displayName : 'Stage ID' ,
name : 'stage_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the stage this deal will be placed in a pipeline. If omitted, the deal will be placed in the first stage of the default pipeline.' ,
} ,
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
options : [
{
name : 'Open' ,
value : 'open' ,
} ,
{
name : 'Won' ,
value : 'won' ,
} ,
{
name : 'Lost' ,
value : 'lost' ,
} ,
{
name : 'Deleted' ,
value : 'deleted' ,
} ,
] ,
default : 'open' ,
description : 'The status of the deal. If not provided it will automatically be set to "open".' ,
} ,
{
displayName : 'User ID' ,
name : 'user_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the user who will be marked as the owner of this deal. If omitted, the authorized user ID will be used.' ,
} ,
{
displayName : 'Value' ,
name : 'value' ,
type : 'number' ,
default : 0 ,
description : 'Value of the deal. If not set it will automatically be set to 0.' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'Visible to' ,
name : 'visible_to' ,
type : 'options' ,
options : [
{
name : 'Owner & followers (private)' ,
value : '1' ,
} ,
{
name : 'Entire company (shared)' ,
value : '3' ,
} ,
] ,
default : '3' ,
2019-07-14 08:57:08 -07:00
description : 'Visibility of the deal. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.' ,
2019-07-10 01:16:48 -07:00
} ,
{
displayName : 'Custom Properties' ,
name : 'customProperties' ,
placeholder : 'Add Custom Property' ,
description : 'Adds a custom property to set also values which have not been predefined.' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
} ,
default : { } ,
options : [
{
name : 'property' ,
displayName : 'Property' ,
values : [
{
displayName : 'Property Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'Name of the property to set.' ,
} ,
{
displayName : 'Property Value' ,
name : 'value' ,
type : 'string' ,
default : '' ,
description : 'Value of the property to set.' ,
} ,
]
} ,
] ,
2019-06-23 12:21:44 -07:00
} ,
] ,
} ,
// ----------------------------------
2019-07-14 08:57:08 -07:00
// deal:delete
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
displayName : 'Deal ID' ,
name : 'dealId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'delete' ,
] ,
resource : [
'deal' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : 0 ,
required : true ,
description : 'ID of the deal to delete.' ,
} ,
2019-07-10 01:16:48 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// deal:get
2019-07-10 01:16:48 -07:00
// ----------------------------------
{
2019-07-14 08:57:08 -07:00
displayName : 'Deal ID' ,
name : 'dealId' ,
2019-07-10 01:16:48 -07:00
type : 'number' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'get'
] ,
resource : [
'deal' ,
2019-07-10 01:16:48 -07:00
] ,
} ,
} ,
default : 0 ,
required : true ,
2019-07-14 08:57:08 -07:00
description : 'ID of the deal to get.' ,
2019-07-10 01:16:48 -07:00
} ,
2019-06-23 12:21:44 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// deal:update
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
2019-07-14 08:57:08 -07:00
displayName : 'Deal ID' ,
name : 'dealId' ,
2019-06-23 12:21:44 -07:00
type : 'number' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'update'
] ,
resource : [
'deal' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : 0 ,
required : true ,
2019-07-14 08:57:08 -07:00
description : 'ID of the deal to update.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-09 23:40:59 -07:00
{
2019-07-14 08:57:08 -07:00
displayName : 'Update Fields' ,
name : 'updateFields' ,
type : 'collection' ,
placeholder : 'Add Field' ,
2019-07-09 23:40:59 -07:00
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'update'
] ,
resource : [
'deal' ,
2019-07-09 23:40:59 -07:00
] ,
} ,
} ,
2019-07-14 08:57:08 -07:00
default : { } ,
options : [
{
displayName : 'Currency' ,
name : 'currency' ,
type : 'string' ,
default : 'USD' ,
description : 'Currency of the deal. Accepts a 3-character currency code. Like EUR, USD, ...' ,
2019-07-09 23:40:59 -07:00
} ,
2019-07-14 08:57:08 -07:00
{
displayName : 'Lost Reason' ,
name : 'lost_reason' ,
type : 'string' ,
default : '' ,
description : 'Reason why the deal was lost.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-14 08:57:08 -07:00
{
displayName : 'Organization ID' ,
name : 'org_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the organization this deal will be associated with.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-14 08:57:08 -07:00
{
displayName : 'Person ID' ,
name : 'person_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the person this deal will be associated with.' ,
2019-07-09 23:40:59 -07:00
} ,
2019-07-14 08:57:08 -07:00
{
displayName : 'Probability' ,
name : 'probability' ,
type : 'number' ,
typeOptions : {
minValue : 0 ,
maxValue : 100 ,
} ,
default : 0 ,
description : 'Deal success probability percentage.' ,
2019-07-09 23:40:59 -07:00
} ,
2019-07-14 08:57:08 -07:00
{
displayName : 'Stage ID' ,
name : 'stage_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the stage this deal will be placed in a pipeline. If omitted, the deal will be placed in the first stage of the default pipeline.' ,
} ,
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
options : [
{
name : 'Open' ,
value : 'open' ,
} ,
{
name : 'Won' ,
value : 'won' ,
} ,
{
name : 'Lost' ,
value : 'lost' ,
} ,
{
name : 'Deleted' ,
value : 'deleted' ,
} ,
2019-06-23 12:21:44 -07:00
] ,
2019-07-14 08:57:08 -07:00
default : 'open' ,
description : 'The status of the deal. If not provided it will automatically be set to "open".' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-14 08:57:08 -07:00
{
displayName : 'Title' ,
name : 'title' ,
type : 'string' ,
default : '' ,
description : 'The title of the deal' ,
} ,
{
displayName : 'Value' ,
name : 'value' ,
type : 'number' ,
default : 0 ,
description : 'Value of the deal. If not set it will automatically be set to 0.' ,
} ,
{
displayName : 'Visible to' ,
name : 'visible_to' ,
type : 'options' ,
options : [
{
name : 'Owner & followers (private)' ,
value : '1' ,
} ,
{
name : 'Entire company (shared)' ,
value : '3' ,
} ,
2019-06-23 12:21:44 -07:00
] ,
2019-07-14 08:57:08 -07:00
default : '3' ,
description : 'Visibility of the deal. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-14 08:57:08 -07:00
{
displayName : 'Custom Properties' ,
name : 'customProperties' ,
placeholder : 'Add Custom Property' ,
description : 'Adds a custom property to set also values which have not been predefined.' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
} ,
default : { } ,
options : [
{
name : 'property' ,
displayName : 'Property' ,
values : [
{
displayName : 'Property Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'Name of the property to set.' ,
} ,
{
displayName : 'Property Value' ,
name : 'value' ,
type : 'string' ,
default : '' ,
description : 'Value of the property to set.' ,
} ,
]
} ,
2019-07-09 23:40:59 -07:00
] ,
} ,
2019-07-14 08:57:08 -07:00
] ,
2019-07-09 23:40:59 -07:00
} ,
2019-07-14 08:57:08 -07:00
2019-06-23 12:21:44 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// organization
2019-06-23 12:21:44 -07:00
// ----------------------------------
// ----------------------------------
2019-07-14 08:57:08 -07:00
// organization:create
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
2019-07-14 08:57:08 -07:00
displayName : 'Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
required : true ,
2019-06-23 12:21:44 -07:00
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'organization' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
2019-07-14 08:57:08 -07:00
description : 'The name of the organization to create' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
2019-06-23 12:21:44 -07:00
type : 'collection' ,
placeholder : 'Add Field' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'organization' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : { } ,
options : [
{
2019-07-14 08:57:08 -07:00
displayName : 'Visible to' ,
name : 'visible_to' ,
2019-06-23 12:21:44 -07:00
type : 'options' ,
options : [
{
2019-07-14 08:57:08 -07:00
name : 'Owner & followers (private)' ,
value : '1' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
name : 'Entire company (shared)' ,
value : '3' ,
2019-06-23 12:21:44 -07:00
} ,
] ,
2019-07-14 08:57:08 -07:00
default : '3' ,
description : 'Visibility of the person. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-10 01:16:48 -07:00
{
displayName : 'Custom Properties' ,
name : 'customProperties' ,
placeholder : 'Add Custom Property' ,
description : 'Adds a custom property to set also values which have not been predefined.' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
} ,
default : { } ,
options : [
{
name : 'property' ,
displayName : 'Property' ,
values : [
{
displayName : 'Property Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'Name of the property to set.' ,
} ,
{
displayName : 'Property Value' ,
name : 'value' ,
type : 'string' ,
default : '' ,
description : 'Value of the property to set.' ,
} ,
]
} ,
] ,
} ,
2019-07-14 08:57:08 -07:00
] ,
} ,
// ----------------------------------
// organization:delete
// ----------------------------------
{
displayName : 'Organization ID' ,
name : 'organizationId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'delete' ,
] ,
resource : [
'organization' ,
] ,
} ,
} ,
default : 0 ,
required : true ,
description : 'ID of the organization to delete.' ,
} ,
// ----------------------------------
// organization:get
// ----------------------------------
{
displayName : 'Organization ID' ,
name : 'organizationId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'get' ,
] ,
resource : [
'organization' ,
] ,
} ,
} ,
default : 0 ,
required : true ,
description : 'ID of the organization to get.' ,
} ,
// ----------------------------------
// organization:getAll
// ----------------------------------
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'organization' ,
] ,
} ,
} ,
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 : [
'organization' ,
] ,
returnAll : [
false ,
] ,
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 500 ,
} ,
default : 100 ,
description : 'How many results to return.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-10 01:16:48 -07:00
2019-07-14 08:57:08 -07:00
// ----------------------------------
// person
// ----------------------------------
2019-06-23 12:21:44 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// person:create
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
2019-07-14 08:57:08 -07:00
displayName : 'Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
required : true ,
2019-06-23 12:21:44 -07:00
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'person' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
2019-07-14 08:57:08 -07:00
description : 'The name of the person to create' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
2019-06-23 12:21:44 -07:00
type : 'collection' ,
placeholder : 'Add Field' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'create' ,
] ,
resource : [
'person' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : { } ,
options : [
{
2019-07-14 08:57:08 -07:00
displayName : 'Email' ,
name : 'email' ,
2019-06-23 12:21:44 -07:00
type : 'string' ,
2019-07-14 08:57:08 -07:00
typeOptions : {
multipleValues : true ,
} ,
2019-06-23 12:21:44 -07:00
default : '' ,
2019-07-14 08:57:08 -07:00
description : 'Email of the person.' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'Organization ID' ,
name : 'org_id' ,
type : 'number' ,
default : 0 ,
2019-07-14 08:57:08 -07:00
description : 'ID of the organization this person will belong to.' ,
2019-06-23 12:21:44 -07:00
} ,
{
2019-07-14 08:57:08 -07:00
displayName : 'Phone' ,
name : 'phone' ,
type : 'string' ,
2019-06-23 12:21:44 -07:00
typeOptions : {
2019-07-14 08:57:08 -07:00
multipleValues : true ,
2019-06-23 12:21:44 -07:00
} ,
default : '' ,
2019-07-14 08:57:08 -07:00
description : 'Phone number of the person.' ,
2019-06-23 12:21:44 -07:00
} ,
{
displayName : 'Visible to' ,
name : 'visible_to' ,
type : 'options' ,
options : [
{
name : 'Owner & followers (private)' ,
value : '1' ,
} ,
{
name : 'Entire company (shared)' ,
value : '3' ,
} ,
] ,
default : '3' ,
2019-07-14 08:57:08 -07:00
description : 'Visibility of the person. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.' ,
2019-06-23 12:21:44 -07:00
} ,
2019-07-10 01:16:48 -07:00
{
displayName : 'Custom Properties' ,
name : 'customProperties' ,
placeholder : 'Add Custom Property' ,
description : 'Adds a custom property to set also values which have not been predefined.' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
} ,
default : { } ,
options : [
{
name : 'property' ,
displayName : 'Property' ,
values : [
{
displayName : 'Property Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'Name of the property to set.' ,
} ,
{
displayName : 'Property Value' ,
name : 'value' ,
type : 'string' ,
default : '' ,
description : 'Value of the property to set.' ,
} ,
]
} ,
] ,
} ,
2019-06-23 12:21:44 -07:00
] ,
} ,
2019-07-14 08:57:08 -07:00
// ----------------------------------
// person:delete
// ----------------------------------
{
displayName : 'Person ID' ,
name : 'personId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'delete' ,
] ,
resource : [
'person' ,
] ,
} ,
} ,
default : 0 ,
required : true ,
description : 'ID of the person to delete.' ,
} ,
// ----------------------------------
// person:get
// ----------------------------------
{
displayName : 'Person ID' ,
name : 'personId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
'get' ,
] ,
resource : [
'person' ,
] ,
} ,
} ,
default : 0 ,
required : true ,
description : 'ID of the person to get.' ,
} ,
// ----------------------------------
// person:getAll
// ----------------------------------
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'person' ,
] ,
} ,
} ,
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 : [
'person' ,
] ,
returnAll : [
false ,
] ,
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 500 ,
} ,
default : 100 ,
description : 'How many results to return.' ,
} ,
2019-06-23 12:21:44 -07:00
// ----------------------------------
2019-07-14 08:57:08 -07:00
// person:update
2019-06-23 12:21:44 -07:00
// ----------------------------------
{
displayName : 'Person ID' ,
name : 'personId' ,
type : 'number' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'update' ,
] ,
resource : [
'person' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : 0 ,
required : true ,
description : 'ID of the person to update.' ,
} ,
{
displayName : 'Update Fields' ,
name : 'updateFields' ,
type : 'collection' ,
2019-07-07 10:01:05 -07:00
description : 'The fields to update.' ,
2019-06-23 12:21:44 -07:00
placeholder : 'Add Field' ,
displayOptions : {
show : {
operation : [
2019-07-14 08:57:08 -07:00
'update' ,
] ,
resource : [
'person' ,
2019-06-23 12:21:44 -07:00
] ,
} ,
} ,
default : { } ,
options : [
{
displayName : 'Email' ,
name : 'email' ,
type : 'string' ,
typeOptions : {
multipleValues : true ,
} ,
default : '' ,
description : 'Email of the person.' ,
} ,
{
displayName : 'Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'The name of the person' ,
} ,
{
displayName : 'Organization ID' ,
name : 'org_id' ,
type : 'number' ,
default : 0 ,
description : 'ID of the organization this person will belong to.' ,
} ,
{
displayName : 'Phone' ,
name : 'phone' ,
type : 'string' ,
typeOptions : {
multipleValues : true ,
} ,
default : '' ,
description : 'Phone number of the person.' ,
} ,
{
displayName : 'Visible to' ,
name : 'visible_to' ,
type : 'options' ,
options : [
{
name : 'Owner & followers (private)' ,
value : '1' ,
} ,
{
name : 'Entire company (shared)' ,
value : '3' ,
} ,
] ,
default : '3' ,
description : 'Visibility of the deal. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.' ,
} ,
2019-07-10 01:16:48 -07:00
{
displayName : 'Custom Properties' ,
name : 'customProperties' ,
placeholder : 'Add Custom Property' ,
description : 'Adds a custom property to set also values which have not been predefined.' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
} ,
default : { } ,
options : [
{
name : 'property' ,
displayName : 'Property' ,
values : [
{
displayName : 'Property Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
description : 'Name of the property to set.' ,
} ,
{
displayName : 'Property Value' ,
name : 'value' ,
type : 'string' ,
default : '' ,
description : 'Value of the property to set.' ,
} ,
]
} ,
] ,
} ,
2019-06-23 12:21:44 -07:00
] ,
} ,
2019-07-14 08:57:08 -07:00
// ----------------------------------
// product
// ----------------------------------
// ----------------------------------
// product:getAll
// ----------------------------------
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
operation : [
'getAll' ,
] ,
resource : [
'product' ,
] ,
} ,
} ,
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 : [
'product' ,
] ,
returnAll : [
false ,
] ,
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 500 ,
} ,
default : 100 ,
description : 'How many results to return.' ,
} ,
2019-06-23 12:21:44 -07:00
] ,
} ;
async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
const items = this . getInputData ( ) ;
const returnData : IDataObject [ ] = [ ] ;
2019-07-14 08:57:08 -07:00
let resource : string ;
let operation : string ;
2019-06-23 12:21:44 -07:00
// For Post
let body : IDataObject ;
// For Query string
let qs : IDataObject ;
let requestMethod : string ;
let endpoint : string ;
let returnAll = false ;
for ( let i = 0 ; i < items . length ; i ++ ) {
2019-07-14 08:57:08 -07:00
resource = this . getNodeParameter ( 'resource' , 0 ) as string ;
operation = this . getNodeParameter ( 'operation' , 0 ) as string ;
2019-06-23 12:21:44 -07:00
requestMethod = 'GET' ;
endpoint = '' ;
body = { } ;
qs = { } ;
2019-07-14 08:57:08 -07:00
if ( resource === 'activity' ) {
if ( operation === 'create' ) {
// ----------------------------------
// activity:create
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'POST' ;
endpoint = '/activities' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
body . subject = this . getNodeParameter ( 'subject' , i ) as string ;
body . done = this . getNodeParameter ( 'done' , i ) as string ;
body . type = this . getNodeParameter ( 'type' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
addAdditionalFields ( body , additionalFields ) ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'delete' ) {
// ----------------------------------
// activity:delete
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'DELETE' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const activityId = this . getNodeParameter ( 'activityId' , i ) as number ;
endpoint = ` /activities/ ${ activityId } ` ;
2019-07-10 01:16:48 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'get' ) {
// ----------------------------------
// activity:get
// ----------------------------------
2019-07-10 01:16:48 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'GET' ;
2019-07-10 01:16:48 -07:00
2019-07-14 08:57:08 -07:00
const activityId = this . getNodeParameter ( 'activityId' , i ) as number ;
endpoint = ` /activities/ ${ activityId } ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'update' ) {
// ----------------------------------
// activity:update
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'PUT' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const activityId = this . getNodeParameter ( 'activityId' , i ) as number ;
endpoint = ` /activities/ ${ activityId } ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
addAdditionalFields ( body , updateFields ) ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
}
} else if ( resource === 'deal' ) {
if ( operation === 'create' ) {
// ----------------------------------
// deal:create
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'POST' ;
endpoint = '/deals' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
body . title = this . getNodeParameter ( 'title' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
addAdditionalFields ( body , additionalFields ) ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'delete' ) {
// ----------------------------------
// deal:delete
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'DELETE' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const dealId = this . getNodeParameter ( 'dealId' , i ) as number ;
endpoint = ` /deals/ ${ dealId } ` ;
2019-07-10 01:16:48 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'get' ) {
// ----------------------------------
// deal:get
// ----------------------------------
2019-07-10 01:16:48 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'GET' ;
2019-07-10 01:16:48 -07:00
2019-07-14 08:57:08 -07:00
const dealId = this . getNodeParameter ( 'dealId' , i ) as number ;
endpoint = ` /deals/ ${ dealId } ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'update' ) {
// ----------------------------------
// deal:update
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'PUT' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const dealId = this . getNodeParameter ( 'dealId' , i ) as number ;
endpoint = ` /deals/ ${ dealId } ` ;
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
addAdditionalFields ( body , updateFields ) ;
2019-07-09 23:40:59 -07:00
}
2019-07-14 08:57:08 -07:00
} else if ( resource === 'organization' ) {
if ( operation === 'create' ) {
// ----------------------------------
// organization:create
// ----------------------------------
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'POST' ;
endpoint = '/organizations' ;
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
body . name = this . getNodeParameter ( 'name' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
addAdditionalFields ( body , additionalFields ) ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'delete' ) {
// ----------------------------------
// organization:delete
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'DELETE' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const organizationId = this . getNodeParameter ( 'organizationId' , i ) as number ;
endpoint = ` /organizations/ ${ organizationId } ` ;
} else if ( operation === 'get' ) {
// ----------------------------------
// organization:get
// ----------------------------------
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'GET' ;
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
const organizationId = this . getNodeParameter ( 'organizationId' , i ) as number ;
endpoint = ` /organizations/ ${ organizationId } ` ;
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'getAll' ) {
// ----------------------------------
// organization:getAll
// ----------------------------------
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'GET' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
returnAll = this . getNodeParameter ( 'returnAll' , i ) as boolean ;
if ( returnAll === false ) {
qs . limit = this . getNodeParameter ( 'limit' , i ) as number ;
}
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
endpoint = ` /organizations ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
}
} else if ( resource === 'person' ) {
if ( operation === 'create' ) {
// ----------------------------------
// person:create
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'POST' ;
endpoint = '/persons' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
body . name = this . getNodeParameter ( 'name' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
addAdditionalFields ( body , additionalFields ) ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'delete' ) {
// ----------------------------------
// person:delete
// ----------------------------------
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'DELETE' ;
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
const personId = this . getNodeParameter ( 'personId' , i ) as number ;
endpoint = ` /persons/ ${ personId } ` ;
2019-07-09 23:40:59 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'get' ) {
// ----------------------------------
// person:get
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'GET' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const personId = this . getNodeParameter ( 'personId' , i ) as number ;
endpoint = ` /persons/ ${ personId } ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'getAll' ) {
// ----------------------------------
// persons:getAll
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'GET' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
returnAll = this . getNodeParameter ( 'returnAll' , i ) as boolean ;
if ( returnAll === false ) {
qs . limit = this . getNodeParameter ( 'limit' , i ) as number ;
}
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
endpoint = ` /persons ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
} else if ( operation === 'update' ) {
// ----------------------------------
// person:update
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'PUT' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const personId = this . getNodeParameter ( 'personId' , i ) as number ;
endpoint = ` /persons/ ${ personId } ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
addAdditionalFields ( body , updateFields ) ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
}
} else if ( resource === 'product' ) {
if ( operation === 'getAll' ) {
// ----------------------------------
// product:getAll
// ----------------------------------
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
requestMethod = 'GET' ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
returnAll = this . getNodeParameter ( 'returnAll' , i ) as boolean ;
if ( returnAll === false ) {
qs . limit = this . getNodeParameter ( 'limit' , i ) as number ;
}
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
endpoint = ` /products ` ;
2019-06-23 12:21:44 -07:00
2019-07-14 08:57:08 -07:00
}
2019-06-23 12:21:44 -07:00
} else {
2019-07-14 08:57:08 -07:00
throw new Error ( ` The resource " ${ resource } " is not known! ` ) ;
2019-06-23 12:21:44 -07:00
}
let responseData ;
if ( returnAll === true ) {
responseData = await pipedriveApiRequestAllItems . call ( this , requestMethod , endpoint , body , qs ) ;
} else {
responseData = await pipedriveApiRequest . call ( this , requestMethod , endpoint , body , qs ) ;
}
if ( Array . isArray ( responseData . data ) ) {
returnData . push . apply ( returnData , responseData . data as IDataObject [ ] ) ;
} else {
returnData . push ( responseData . data as IDataObject ) ;
}
}
return [ this . helpers . returnJsonArray ( returnData ) ] ;
}
}