UNPKG

n8n-nodes-rd-station-crm

Version:

n8n community node for RD Station CRM: API v1 (private token) and API v2 (OAuth2) — contacts, deals, organizations, tasks, notes, pipelines, stages, products, custom fields, sources, campaigns, loss reasons, users, teams and a real webhook trigger.

214 lines 9.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.taskV2Description = void 0; exports.executeTaskV2 = executeTaskV2; const v2_1 = require("../../transport/v2"); // --------------------------------------------------------------------------- // v2 (OAuth2) Task resource — mirrors the ContactV2 template: // - resource value ends in "V2" (taskV2) so it never collides with v1 // - fields gated by displayOptions.show.resource = ['taskV2'] // - execute uses the v2 transport (Bearer, { data } envelope, links.next paging) // --------------------------------------------------------------------------- const showOnly = { resource: ['taskV2'] }; const taskTypeOptions = [ { name: 'Call', value: 'call' }, { name: 'Email', value: 'email' }, { name: 'Lunch', value: 'lunch' }, { name: 'Meeting', value: 'meeting' }, { name: 'Task', value: 'task' }, { name: 'Visit', value: 'visit' }, { name: 'WhatsApp', value: 'whatsapp' }, ]; exports.taskV2Description = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: showOnly }, options: [ { name: 'Create', value: 'create', action: 'Create a task', description: 'Create a new task (activity) in RD Station CRM (API v2) and return the created record' }, { name: 'Get', value: 'get', action: 'Get a task', description: 'Retrieve a single task by its ID from RD Station CRM (API v2)' }, { name: 'Get Many', value: 'getMany', action: 'Get many tasks', description: 'Retrieve a paginated list of tasks from RD Station CRM (API v2)' }, { name: 'Update', value: 'update', action: 'Update a task', description: 'Update fields of an existing task in RD Station CRM (API v2)' }, ], default: 'create', }, { displayName: 'Task ID', name: 'taskId', type: 'string', required: true, default: '', displayOptions: { show: { ...showOnly, operation: ['get', 'update'] } }, description: 'Unique identifier of the task to operate on, taken from the ID returned by a create or get tasks operation', }, { displayName: 'Name', name: 'name', type: 'string', required: true, default: '', displayOptions: { show: { ...showOnly, operation: ['create'] } }, description: 'Title of the task to create, for example Call the client about the proposal', }, { displayName: 'Type', name: 'type', type: 'options', default: 'task', options: taskTypeOptions, displayOptions: { show: { ...showOnly, operation: ['create'] } }, description: 'Kind of activity for the task. One of: call, email, lunch, meeting, task, visit, whatsapp', }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', default: {}, displayOptions: { show: { ...showOnly, operation: ['create'] } }, options: [ { displayName: 'Deal ID', name: 'deal_id', type: 'string', default: '', description: 'ID of the deal to link this task to, taken from a deal create or get operation' }, { displayName: 'Description', name: 'description', type: 'string', default: '', description: 'Free-text details of the task' }, { displayName: 'Due Date', name: 'due_date', type: 'dateTime', default: '', description: 'Due date of the task in ISO 8601 format, e.g. 2026-07-08 or 2026-07-08T14:30:00Z' }, { displayName: 'Owner IDs', name: 'owner_ids', type: 'string', default: '', description: 'Comma-separated list of user IDs to assign as owners of the task', }, ], }, { displayName: 'Update Fields', name: 'updateFields', type: 'collection', placeholder: 'Add Field', default: {}, displayOptions: { show: { ...showOnly, operation: ['update'] } }, options: [ { displayName: 'Deal ID', name: 'deal_id', type: 'string', default: '', description: 'ID of the deal to link this task to, taken from a deal create or get operation' }, { displayName: 'Description', name: 'description', type: 'string', default: '', description: 'Free-text details of the task' }, { displayName: 'Due Date', name: 'due_date', type: 'dateTime', default: '', description: 'Due date of the task in ISO 8601 format, e.g. 2026-07-08 or 2026-07-08T14:30:00Z' }, { displayName: 'Name', name: 'name', type: 'string', default: '', description: 'New title for the task, e.g. Call the client about the proposal' }, { displayName: 'Owner IDs', name: 'owner_ids', type: 'string', default: '', description: 'Comma-separated list of user IDs to assign as owners of the task', }, { displayName: 'Status', name: 'status', type: 'options', default: 'open', options: [ { name: 'Canceled', value: 'canceled' }, { name: 'Completed', value: 'completed' }, { name: 'Open', value: 'open' }, ], description: 'Status of the task. One of: canceled, completed, open', }, { displayName: 'Type', name: 'type', type: 'options', default: 'task', options: taskTypeOptions, description: 'Kind of activity for the task. One of: call, email, lunch, meeting, task, visit, whatsapp', }, ], }, { displayName: 'Return All', name: 'returnAll', type: 'boolean', default: false, description: 'Whether to return all results or only up to a given limit', displayOptions: { show: { ...showOnly, operation: ['getMany'] } }, }, { displayName: 'Limit', name: 'limit', type: 'number', default: 50, typeOptions: { minValue: 1 }, description: 'Max number of results to return', displayOptions: { show: { ...showOnly, operation: ['getMany'], returnAll: [false] } }, }, { displayName: 'Filters', name: 'filters', type: 'collection', placeholder: 'Add Filter', default: {}, displayOptions: { show: { ...showOnly, operation: ['getMany'] } }, options: [ { displayName: 'RDQL Filter', name: 'filter', type: 'string', default: '', placeholder: 'e.g. name:~Follow up', description: 'RDQL filter expression to narrow the tasks returned, for example <code>name:~Follow up</code>, see the RD Station CRM v2 docs', }, ], }, ]; function buildTaskV2Body(fields) { const task = {}; for (const key of ['name', 'description', 'type', 'deal_id', 'status']) { if (fields[key]) task[key] = fields[key]; } if (fields.due_date) { task.due_date = new Date(fields.due_date).toISOString(); } if (fields.owner_ids) { task.owner_ids = fields.owner_ids .split(',') .map((s) => s.trim()) .filter(Boolean); } return task; } async function executeTaskV2(operation, i) { if (operation === 'create') { const name = this.getNodeParameter('name', i); const type = this.getNodeParameter('type', i); const additionalFields = this.getNodeParameter('additionalFields', i, {}); const body = buildTaskV2Body({ name, type, ...additionalFields }); const response = await v2_1.rdCrmV2Request.call(this, 'POST', '/tasks', body); return response.data ?? response; } if (operation === 'get') { const taskId = this.getNodeParameter('taskId', i); const response = await v2_1.rdCrmV2Request.call(this, 'GET', `/tasks/${taskId}`); return response.data ?? response; } if (operation === 'getMany') { const returnAll = this.getNodeParameter('returnAll', i); const filters = this.getNodeParameter('filters', i, {}); const qs = {}; if (filters.filter) qs.filter = filters.filter; if (returnAll) { return v2_1.rdCrmV2RequestAllItems.call(this, '/tasks', qs); } qs['page[size]'] = this.getNodeParameter('limit', i); const response = await v2_1.rdCrmV2Request.call(this, 'GET', '/tasks', {}, qs); return response.data ?? response; } if (operation === 'update') { const taskId = this.getNodeParameter('taskId', i); const updateFields = this.getNodeParameter('updateFields', i, {}); const body = buildTaskV2Body({ ...updateFields }); const response = await v2_1.rdCrmV2Request.call(this, 'PUT', `/tasks/${taskId}`, body); return response.data ?? response; } return {}; } //# sourceMappingURL=TaskV2.js.map