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.
309 lines • 13.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.organizationDescription = void 0;
exports.executeOrganization = executeOrganization;
const transport_1 = require("../../transport");
const showOnlyForOrganizations = {
resource: ['organization'],
};
exports.organizationDescription = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: { show: showOnlyForOrganizations },
options: [
{
name: 'Create',
value: 'create',
action: 'Create an organization',
description: 'Create a new organization (company or account) in RD Station CRM and return the created record including its ID',
},
{
name: 'Get',
value: 'get',
action: 'Get an organization',
description: 'Retrieve a single organization from RD Station CRM by its unique ID',
},
{
name: 'Get Contacts',
value: 'getContacts',
action: 'Get contacts of an organization',
description: 'Retrieve the contacts (people) linked to a given organization in RD Station CRM',
},
{
name: 'Get Many',
value: 'getMany',
action: 'Get many organizations',
description: 'Retrieve a paginated list of organizations from RD Station CRM, with optional filters and sorting',
},
{
name: 'Update',
value: 'update',
action: 'Update an organization',
description: 'Update an existing RD Station CRM organization identified by its ID and return the updated record',
},
],
default: 'create',
},
// ----- ID field (get / update / getContacts) -----
{
displayName: 'Organization ID',
name: 'organizationId',
type: 'string',
required: true,
default: '',
displayOptions: {
show: { ...showOnlyForOrganizations, operation: ['get', 'update', 'getContacts'] },
},
description: 'Unique ID of the organization to retrieve, update, or list contacts for, as returned by a Create or Get Many organization operation',
},
// ----- name (create) -----
{
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
default: '',
displayOptions: { show: { ...showOnlyForOrganizations, operation: ['create'] } },
description: 'Name of the organization (company or account), for example Acme Ltda',
},
// ----- Custom Fields (create + update) -----
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
type: 'fixedCollection',
typeOptions: { multipleValues: true },
placeholder: 'Add Custom Field',
default: {},
displayOptions: { show: { ...showOnlyForOrganizations, operation: ['create', 'update'] } },
options: [
{
name: 'field',
displayName: 'Field',
values: [
{
displayName: 'Field Name or ID',
name: 'fieldId',
type: 'options',
description: 'Organization custom field to set, referenced by its custom field ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: { loadOptionsMethod: 'getOrganizationCustomFields' },
default: '',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value to set for the selected custom field, as plain text, e.g. Enterprise',
},
],
},
],
},
// ----- Additional / Update fields -----
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: { show: { ...showOnlyForOrganizations, operation: ['create'] } },
options: [
{ displayName: 'Resume', name: 'resume', type: 'string', default: '', description: 'Short text description or summary of the organization' },
{
displayName: 'Segments',
name: 'organizationSegments',
type: 'string',
default: '',
description: 'Comma-separated list of segment names to link to the organization, for example Enterprise,Priority',
},
{ displayName: 'URL', name: 'url', type: 'string', default: '', description: 'Full website URL including the https:// scheme, e.g. https://www.empresa.com' },
{
displayName: 'User Name or ID',
name: 'userId',
type: 'options',
description: 'CRM user who owns the organization, referenced by user ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: { loadOptionsMethod: 'getUsers' },
default: '',
},
],
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: { show: { ...showOnlyForOrganizations, operation: ['update'] } },
options: [
{ displayName: 'Name', name: 'name', type: 'string', default: '', description: 'Name of the organization (company or account), e.g. Acme Ltda' },
{ displayName: 'Resume', name: 'resume', type: 'string', default: '', description: 'Short text description or summary of the organization' },
{
displayName: 'Segments',
name: 'organizationSegments',
type: 'string',
default: '',
description: 'Comma-separated list of segment names to link to the organization, for example Enterprise,Priority',
},
{ displayName: 'URL', name: 'url', type: 'string', default: '', description: 'Full website URL including the https:// scheme, e.g. https://www.empresa.com' },
{
displayName: 'User Name or ID',
name: 'userId',
type: 'options',
description: 'CRM user who owns the organization, referenced by user ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: { loadOptionsMethod: 'getUsers' },
default: '',
},
],
},
// ----- Get Many / Get Contacts 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: { ...showOnlyForOrganizations, operation: ['getMany', 'getContacts'] } },
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 50,
typeOptions: { minValue: 1 },
description: 'Max number of results to return',
displayOptions: {
show: {
...showOnlyForOrganizations,
operation: ['getMany', 'getContacts'],
returnAll: [false],
},
},
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: { show: { ...showOnlyForOrganizations, operation: ['getMany'] } },
options: [
{ displayName: 'Search', name: 'q', type: 'string', default: '', description: 'Filter organizations by name, returning those whose name matches the given text' },
{
displayName: 'User Name or ID',
name: 'userId',
type: 'options',
description: 'CRM user who owns the organization, referenced by user ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: { loadOptionsMethod: 'getUsers' },
default: '',
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: { show: { ...showOnlyForOrganizations, operation: ['getMany'] } },
options: [
{
displayName: 'Sort By',
name: 'order',
type: 'options',
options: [
{ name: 'Created At', value: 'created_at' },
{ name: 'Name', value: 'name' },
{ name: 'Updated At', value: 'updated_at' },
],
default: 'name',
description: 'Field to sort the results by. One of: created_at, name, updated_at',
},
{
displayName: 'Sort Direction',
name: 'direction',
type: 'options',
options: [
{ name: 'Ascending', value: 'asc' },
{ name: 'Descending', value: 'desc' },
],
default: 'asc',
description: 'Sort direction. One of: asc, desc',
},
],
},
];
function buildOrganizationBody(i, fields) {
const organization = {};
if (fields.name)
organization.name = fields.name;
if (fields.resume)
organization.resume = fields.resume;
if (fields.url)
organization.url = fields.url;
if (fields.userId)
organization.user_id = fields.userId;
if (fields.organizationSegments) {
organization.organization_segments = fields.organizationSegments
.split(',')
.map((s) => s.trim())
.filter(Boolean);
}
const customFieldsUi = this.getNodeParameter('customFieldsUi', i, {});
if (Array.isArray(customFieldsUi.field)) {
organization.organization_custom_fields = customFieldsUi.field.map((f) => ({
custom_field_id: f.fieldId,
value: f.value,
}));
}
return organization;
}
async function executeOrganization(operation, i) {
if (operation === 'create') {
const name = this.getNodeParameter('name', i);
const additionalFields = this.getNodeParameter('additionalFields', i, {});
const organization = buildOrganizationBody.call(this, i, { name, ...additionalFields });
return transport_1.rdCrmApiRequest.call(this, 'POST', '/organizations', { organization });
}
if (operation === 'get') {
const organizationId = this.getNodeParameter('organizationId', i);
return transport_1.rdCrmApiRequest.call(this, 'GET', `/organizations/${organizationId}`);
}
if (operation === 'getMany') {
const returnAll = this.getNodeParameter('returnAll', i);
const filters = this.getNodeParameter('filters', i, {});
const options = this.getNodeParameter('options', i, {});
const qs = { ...options };
if (filters.q)
qs.q = filters.q;
if (filters.userId)
qs.user_id = filters.userId;
if (returnAll) {
return transport_1.rdCrmApiRequestAllItems.call(this, 'organizations', 'GET', '/organizations', {}, qs);
}
qs.limit = this.getNodeParameter('limit', i);
const response = await transport_1.rdCrmApiRequest.call(this, 'GET', '/organizations', {}, qs);
return response.organizations ?? response;
}
if (operation === 'update') {
const organizationId = this.getNodeParameter('organizationId', i);
const updateFields = this.getNodeParameter('updateFields', i, {});
const organization = buildOrganizationBody.call(this, i, updateFields);
return transport_1.rdCrmApiRequest.call(this, 'PUT', `/organizations/${organizationId}`, { organization });
}
if (operation === 'getContacts') {
const organizationId = this.getNodeParameter('organizationId', i);
const returnAll = this.getNodeParameter('returnAll', i);
const endpoint = `/organizations/${organizationId}/contacts`;
if (returnAll) {
return transport_1.rdCrmApiRequestAllItems.call(this, 'contacts', 'GET', endpoint);
}
const qs = { limit: this.getNodeParameter('limit', i) };
const response = await transport_1.rdCrmApiRequest.call(this, 'GET', endpoint, {}, qs);
return response.contacts ?? response;
}
return {};
}
//# sourceMappingURL=Organization.js.map