n8n-nodes-base
Version:
Base nodes of n8n
1,280 lines (1,279 loc) • 199 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pipedrive = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const GenericFunctions_1 = require("./GenericFunctions");
const utils_1 = require("./utils");
/**
* 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, additionalFields) {
for (const key of Object.keys(additionalFields)) {
if (key === 'customProperties' &&
additionalFields.customProperties.property !== undefined) {
for (const customProperty of additionalFields.customProperties
.property) {
body[customProperty.name] = customProperty.value;
}
}
else {
body[key] = additionalFields[key];
}
}
}
class Pipedrive {
description = {
displayName: 'Pipedrive',
name: 'pipedrive',
icon: 'file:pipedrive.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Create and edit data in Pipedrive',
defaults: {
name: 'Pipedrive',
},
usableAsTool: true,
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
credentials: [
{
name: 'pipedriveApi',
required: true,
displayOptions: {
show: {
authentication: ['apiToken'],
},
},
testedBy: {
request: {
method: 'GET',
url: '/users/me',
},
},
},
{
name: 'pipedriveOAuth2Api',
required: true,
displayOptions: {
show: {
authentication: ['oAuth2'],
},
},
},
],
requestDefaults: {
baseURL: 'https://api.pipedrive.com/v1',
url: '',
},
properties: [
{
displayName: 'Authentication',
name: 'authentication',
type: 'options',
options: [
{
name: 'API Token',
value: 'apiToken',
},
{
name: 'OAuth2',
value: 'oAuth2',
},
],
default: 'apiToken',
},
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Activity',
value: 'activity',
},
{
name: 'Deal',
value: 'deal',
},
{
name: 'Deal Activity',
value: 'dealActivity',
},
{
name: 'Deal Product',
value: 'dealProduct',
},
{
name: 'File',
value: 'file',
},
{
name: 'Lead',
value: 'lead',
},
{
name: 'Note',
value: 'note',
},
{
name: 'Organization',
value: 'organization',
},
{
name: 'Person',
value: 'person',
},
{
name: 'Product',
value: 'product',
},
],
default: 'deal',
},
// ----------------------------------
// operations
// ----------------------------------
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['activity'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create an activity',
action: 'Create an activity',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete an activity',
action: 'Delete an activity',
},
{
name: 'Get',
value: 'get',
description: 'Get data of an activity',
action: 'Get an activity',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get data of many activities',
action: 'Get many activities',
},
{
name: 'Update',
value: 'update',
description: 'Update an activity',
action: 'Update an activity',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['deal'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a deal',
action: 'Create a deal',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a deal',
action: 'Delete a deal',
},
{
name: 'Duplicate',
value: 'duplicate',
description: 'Duplicate a deal',
action: 'Duplicate a deal',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a deal',
action: 'Get a deal',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get data of many deals',
action: 'Get many deals',
},
{
name: 'Search',
value: 'search',
description: 'Search a deal',
action: 'Search a deal',
},
{
name: 'Update',
value: 'update',
description: 'Update a deal',
action: 'Update a deal',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['dealActivity'],
},
},
options: [
{
name: 'Get Many',
value: 'getAll',
description: 'Get many activities of a deal',
action: 'Get many deal activities',
},
],
default: 'getAll',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['dealProduct'],
},
},
options: [
{
name: 'Add',
value: 'add',
description: 'Add a product to a deal',
action: 'Add a deal product',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many products in a deal',
action: 'Get many deal products',
},
{
name: 'Remove',
value: 'remove',
description: 'Remove a product from a deal',
action: 'Remove a deal product',
},
{
name: 'Update',
value: 'update',
description: 'Update a product in a deal',
action: 'Update a deal product',
},
],
default: 'add',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['file'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a file',
action: 'Create a file',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a file',
action: 'Delete a file',
},
{
name: 'Download',
value: 'download',
description: 'Download a file',
action: 'Download a file',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a file',
action: 'Get a file',
},
{
name: 'Update',
value: 'update',
description: 'Update file details',
action: 'update details of a file',
},
// {
// name: 'Get All',
// value: 'getAll',
// description: 'Get data of all file',
// },
// {
// name: 'Update',
// value: 'update',
// description: 'Update a file',
// },
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['lead'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a lead',
action: 'Create a lead',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a lead',
action: 'Delete a lead',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a lead',
action: 'Get a lead',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get data of many leads',
action: 'Get many leads',
},
{
name: 'Update',
value: 'update',
description: 'Update a lead',
action: 'Update a lead',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['note'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a note',
action: 'Create a note',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a note',
action: 'Delete a note',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a note',
action: 'Get a note',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get data of many notes',
action: 'Get many notes',
},
{
name: 'Update',
value: 'update',
description: 'Update a note',
action: 'Update a note',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['organization'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create an organization',
action: 'Create an organization',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete an organization',
action: 'Delete an organization',
},
{
name: 'Get',
value: 'get',
description: 'Get data of an organization',
action: 'Get an organization',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get data of many organizations',
action: 'Get many organizations',
},
{
name: 'Search',
value: 'search',
description: 'Search organizations',
action: 'Search an organization',
},
{
name: 'Update',
value: 'update',
description: 'Update an organization',
action: 'Update an organization',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['person'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a person',
action: 'Create a person',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a person',
action: 'Delete a person',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a person',
action: 'Get a person',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get data of many persons',
action: 'Get many people',
},
{
name: 'Search',
value: 'search',
description: 'Search all persons',
action: 'Search a person',
},
{
name: 'Update',
value: 'update',
description: 'Update a person',
action: 'Update a person',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['product'],
},
},
options: [
{
name: 'Get Many',
value: 'getAll',
description: 'Get data of many products',
action: 'Get many products',
},
],
default: 'getAll',
},
// ----------------------------------
// Activity
// ----------------------------------
// ----------------------------------
// activity:create
// ----------------------------------
{
displayName: 'Subject',
name: 'subject',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: ['create'],
resource: ['activity'],
},
},
description: 'The subject of the activity to create',
},
{
displayName: 'Done',
name: 'done',
type: 'options',
displayOptions: {
show: {
operation: ['create'],
resource: ['activity'],
},
},
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: ['create'],
resource: ['activity'],
},
},
placeholder: 'call',
description: 'Type of the activity like "call", "meeting", etc',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: ['create'],
resource: ['activity'],
},
},
default: {},
options: [
{
displayName: 'Deal ID',
name: 'deal_id',
type: 'number',
default: 0,
description: 'ID of the deal this activity will be associated with',
},
{
displayName: 'Due Date',
name: 'due_date',
type: 'dateTime',
default: '',
description: 'Due Date to activity be done YYYY-MM-DD',
},
{
displayName: 'Note',
name: 'note',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'Note of the activity (HTML format)',
},
{
displayName: 'Organization Name or ID',
name: 'org_id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getOrganizationIds',
},
default: '',
description: 'ID of the organization this activity will be associated with. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Person ID',
name: 'person_id',
type: 'number',
default: 0,
description: 'ID of the person this activity will be associated with',
},
{
displayName: 'User Name or ID',
name: 'user_id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUserIds',
},
default: '',
description: 'ID of the active user whom the activity will be assigned to. If omitted, the activity will be assigned to the authorized user. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
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',
},
],
},
],
},
],
},
// ----------------------------------
// 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',
},
// ----------------------------------
// activity:get
// ----------------------------------
{
displayName: 'Activity ID',
name: 'activityId',
type: 'number',
displayOptions: {
show: {
operation: ['get'],
resource: ['activity'],
},
},
default: 0,
required: true,
description: 'ID of the activity to get',
},
// ----------------------------------
// activity:update
// ----------------------------------
{
displayName: 'Activity ID',
name: 'activityId',
type: 'number',
displayOptions: {
show: {
operation: ['update'],
resource: ['activity'],
},
},
default: 0,
required: true,
description: 'ID of the activity to update',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: ['update'],
resource: ['activity'],
},
},
default: {},
options: [
{
displayName: 'Busy Flag',
name: 'busy_flag',
type: 'boolean',
default: false,
description: 'Whether the user is set to busy during the activity',
},
{
displayName: 'Deal ID',
name: 'deal_id',
type: 'number',
default: 0,
description: 'ID of the deal this activity will be associated with',
},
{
displayName: 'Due Date',
name: 'due_date',
type: 'dateTime',
default: '',
description: 'Due Date to activity be done YYYY-MM-DD',
},
{
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',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'Note of the activity (HTML format)',
},
{
displayName: 'Organization Name or ID',
name: 'org_id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getOrganizationIds',
},
default: '',
description: 'ID of the organization this activity will be associated with. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Person ID',
name: 'person_id',
type: 'number',
default: 0,
description: 'ID of the person this activity will be associated with',
},
{
displayName: 'Public Description',
name: 'public_description',
type: 'string',
default: '',
description: 'Additional details about the activity that is synced to your external calendar',
},
{
displayName: 'Subject',
name: 'subject',
type: 'string',
default: '',
description: 'The subject of the activity',
},
{
displayName: 'Type',
name: 'type',
type: 'string',
default: '',
placeholder: 'call',
description: 'Type of the activity like "call", "meeting", etc',
},
{
displayName: 'User Name or ID',
name: 'user_id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUserIds',
},
default: '',
description: 'ID of the active user whom the activity will be assigned to. If omitted, the activity will be assigned to the authorized user. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
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',
},
],
},
],
},
],
},
// ----------------------------------
// deal
// ----------------------------------
// ----------------------------------
// deal:create
// ----------------------------------
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: ['create'],
resource: ['deal'],
},
},
description: 'The title of the deal to create',
},
{
displayName: 'Associate With',
name: 'associateWith',
type: 'options',
options: [
{
name: 'Organization',
value: 'organization',
},
{
name: 'Person',
value: 'person',
},
],
default: 'organization',
description: 'Type of entity to link to this deal',
required: true,
displayOptions: {
show: {
resource: ['deal'],
operation: ['create'],
},
},
},
{
displayName: 'Organization ID',
name: 'org_id',
type: 'number',
default: 0,
description: 'ID of the organization this deal will be associated with',
required: true,
displayOptions: {
show: {
operation: ['create'],
resource: ['deal'],
associateWith: ['organization'],
},
},
},
{
displayName: 'Person ID',
name: 'person_id',
type: 'number',
default: 0,
description: 'ID of the person this deal will be associated with',
displayOptions: {
show: {
operation: ['create'],
resource: ['deal'],
associateWith: ['person'],
},
},
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: ['create'],
resource: ['deal'],
},
},
default: {},
options: [
{
displayName: 'Currency',
name: 'currency',
type: 'string',
default: 'USD',
description: 'Currency of the deal. Accepts a 3-character currency code. Like EUR, USD, ...',
},
{
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 or ID',
name: 'name',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getDealCustomFields',
},
default: '',
description: 'Name of the property to set. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Property Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the property to set',
},
],
},
],
},
{
displayName: 'Label Name or ID',
name: 'label',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getDealLabels',
},
default: '',
},
{
displayName: 'Lost Reason',
name: 'lost_reason',
type: 'string',
default: '',
description: 'Reason why the deal was lost',
},
{
displayName: 'Organization ID',
name: 'org_id',
type: 'number',
default: 0,
displayOptions: {
show: {
'/associateWith': ['person'],
},
},
description: 'ID of the organization this deal will be associated with',
},
{
displayName: 'Person ID',
name: 'person_id',
type: 'number',
default: 0,
displayOptions: {
show: {
'/associateWith': ['organization'],
},
},
description: 'ID of the person this deal will be associated with',
},
{
displayName: 'Probability',
name: 'probability',
type: 'number',
typeOptions: {
minValue: 0,
maxValue: 100,
},
default: 0,
description: 'Deal success probability percentage',
},
{
displayName: 'Stage Name or ID',
name: 'stage_id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getStageIds',
},
default: '',
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. (PIPELINE > STAGE). Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
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 Name or ID',
name: 'user_id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUserIds',
},
default: '',
description: 'ID of the active user whom the activity will be assigned to. If omitted, the activity will be assigned to the authorized user. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
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',
},
],
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.',
},
],
},
// ----------------------------------
// deal:delete
// ----------------------------------
{
displayName: 'Deal ID',
name: 'dealId',
type: 'number',
displayOptions: {
show: {
operation: ['delete'],
resource: ['deal'],
},
},
default: 0,
required: true,
description: 'ID of the deal to delete',
},
// ----------------------------------
// deal:duplicate
// ----------------------------------
{
displayName: 'Deal ID',
name: 'dealId',
type: 'number',
displayOptions: {
show: {
operation: ['duplicate'],
resource: ['deal'],
},
},
default: 0,
required: true,
description: 'ID of the deal to duplicate',
},
// ----------------------------------
// deal:get
// ----------------------------------
{
displayName: 'Deal ID',
name: 'dealId',
type: 'number',
displayOptions: {
show: {
operation: ['get'],
resource: ['deal'],
},
},
default: 0,
required: true,
description: 'ID of the deal to get',
},
// ----------------------------------
// deal:update
// ----------------------------------
{
displayName: 'Deal ID',
name: 'dealId',
type: 'number',
displayOptions: {
show: {
operation: ['update'],
resource: ['deal'],
},
},
default: 0,
required: true,
description: 'ID of the deal to update',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: ['update'],
resource: ['deal'],
},
},
default: {},
options: [
{
displayName: 'Currency',
name: 'currency',
type: 'string',
default: 'USD',
description: 'Currency of the deal. Accepts a 3-character currency code. Like EUR, USD, ...',
},
{
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 or ID',
name: 'name',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getDealCustomFields',
},
default: '',
description: 'Name of the custom field to set. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{