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.

166 lines 6.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lossReasonDescription = void 0; exports.executeLossReason = executeLossReason; const transport_1 = require("../../transport"); const showOnlyForLossReasons = { resource: ['lossReason'], }; exports.lossReasonDescription = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: showOnlyForLossReasons }, options: [ { name: 'Create', value: 'create', action: 'Create a loss reason', description: 'Create a new deal loss reason in RD Station CRM explaining why deals are lost, and return the created reason', }, { name: 'Get', value: 'get', action: 'Get a loss reason', description: 'Retrieve a single deal loss reason from RD Station CRM by its ID', }, { name: 'Get Many', value: 'getMany', action: 'Get many loss reasons', description: 'Retrieve a paginated list of deal loss reasons from RD Station CRM, with an optional name search filter', }, { name: 'Update', value: 'update', action: 'Update a loss reason', description: 'Update the name of an existing deal loss reason in RD Station CRM by its ID', }, ], default: 'create', }, // ----- ID field (get / update) ----- { displayName: 'Loss Reason ID', name: 'lossReasonId', type: 'string', required: true, default: '', displayOptions: { show: { ...showOnlyForLossReasons, operation: ['get', 'update'] } }, description: 'ID of the deal loss reason to operate on, obtained from a create or get many loss reasons operation', }, // ----- name (create) ----- { displayName: 'Name', name: 'name', type: 'string', required: true, default: '', displayOptions: { show: { ...showOnlyForLossReasons, operation: ['create'] } }, description: 'Text describing why a deal was lost, between 2 and 40 characters, for example Price too high', }, // ----- Update fields ----- { displayName: 'Update Fields', name: 'updateFields', type: 'collection', placeholder: 'Add Field', default: {}, displayOptions: { show: { ...showOnlyForLossReasons, operation: ['update'] } }, options: [ { displayName: 'Name', name: 'name', type: 'string', default: '', description: 'Text describing why a deal was lost, between 2 and 40 characters, for example Price too high', }, ], }, // ----- Get Many controls ----- { displayName: 'Return All', name: 'returnAll', type: 'boolean', default: false, description: 'Whether to return all results or only up to a given limit', displayOptions: { show: { ...showOnlyForLossReasons, operation: ['getMany'] } }, }, { displayName: 'Limit', name: 'limit', type: 'number', default: 50, typeOptions: { minValue: 1 }, description: 'Max number of results to return', displayOptions: { show: { ...showOnlyForLossReasons, operation: ['getMany'], returnAll: [false] }, }, }, { displayName: 'Filters', name: 'filters', type: 'collection', placeholder: 'Add Filter', default: {}, displayOptions: { show: { ...showOnlyForLossReasons, operation: ['getMany'] } }, options: [ { displayName: 'Search', name: 'q', type: 'string', default: '', description: 'Return only deal loss reasons whose name matches this search text' }, ], }, { displayName: 'Options', name: 'options', type: 'collection', placeholder: 'Add Option', default: {}, displayOptions: { show: { ...showOnlyForLossReasons, operation: ['getMany'] } }, options: [ { displayName: 'Sort By', name: 'order', type: 'options', options: [ { name: 'Name', value: 'name' }, ], default: 'name', description: 'Field to sort the returned deal loss reasons by. One of: name', }, ], }, ]; async function executeLossReason(operation, i) { if (operation === 'create') { const name = this.getNodeParameter('name', i); // Body is sent top-level (no wrapper). The deal lost reasons docs list `name` // (2-40 chars) as the only top-level body param (mirrors the campaigns shape). const body = { name }; return transport_1.rdCrmApiRequest.call(this, 'POST', '/deal_lost_reasons', body); } if (operation === 'get') { const lossReasonId = this.getNodeParameter('lossReasonId', i); return transport_1.rdCrmApiRequest.call(this, 'GET', `/deal_lost_reasons/${lossReasonId}`); } if (operation === 'getMany') { const returnAll = this.getNodeParameter('returnAll', i); const filters = this.getNodeParameter('filters', i, {}); const options = this.getNodeParameter('options', i, {}); const qs = { ...filters, ...options }; if (returnAll) { return transport_1.rdCrmApiRequestAllItems.call(this, 'deal_lost_reasons', 'GET', '/deal_lost_reasons', {}, qs); } qs.limit = this.getNodeParameter('limit', i); const response = await transport_1.rdCrmApiRequest.call(this, 'GET', '/deal_lost_reasons', {}, qs); return response.deal_lost_reasons ?? response; } if (operation === 'update') { const lossReasonId = this.getNodeParameter('lossReasonId', i); const updateFields = this.getNodeParameter('updateFields', i, {}); // Body is sent top-level (no wrapper), matching the create request shape. return transport_1.rdCrmApiRequest.call(this, 'PUT', `/deal_lost_reasons/${lossReasonId}`, updateFields); } return {}; } //# sourceMappingURL=LossReason.js.map