mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-23 10:32:17 -08:00
⚡ Improve AgileCrm-Node
This commit is contained in:
parent
f66ed93b0a
commit
7b4980690f
|
@ -16,10 +16,5 @@
|
|||
"lerna": "^3.13.1",
|
||||
"run-script-os": "^1.0.7"
|
||||
},
|
||||
"postcss": {},
|
||||
"dependencies": {
|
||||
"@typescript-eslint/parser": "^2.31.0",
|
||||
"tslint-eslint-rules": "^5.4.0",
|
||||
"typescript-tslint-plugin": "^0.5.5"
|
||||
}
|
||||
"postcss": {}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
} from './DealDescription';
|
||||
|
||||
import { IContact, IContactUpdate } from './ContactInterface';
|
||||
import { agileCrmApiRequest, agileCrmApiRequestUpdate, validateJSON} from './GenericFunctions';
|
||||
import { agileCrmApiRequest, agileCrmApiRequestUpdate, validateJSON } from './GenericFunctions';
|
||||
import { IDeal } from './DealInterface';
|
||||
|
||||
|
||||
|
@ -90,36 +90,31 @@ export class AgileCrm implements INodeType {
|
|||
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
let responseData;
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
|
||||
if(resource === 'contact' || resource === 'company'){
|
||||
if (resource === 'contact' || resource === 'company') {
|
||||
const idGetter = resource === 'contact' ? 'contactId' : 'companyId';
|
||||
|
||||
if(operation === 'get'){
|
||||
if (operation === 'get') {
|
||||
const contactId = this.getNodeParameter(idGetter, i) as string;
|
||||
|
||||
const endpoint = `api/contacts/${contactId}`;
|
||||
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
|
||||
|
||||
}
|
||||
|
||||
if(operation === 'delete'){
|
||||
} else if (operation === 'delete') {
|
||||
const contactId = this.getNodeParameter(idGetter, i) as string;
|
||||
|
||||
const endpoint = `api/contacts/${contactId}`;
|
||||
responseData = await agileCrmApiRequest.call(this, 'DELETE', endpoint, {});
|
||||
|
||||
}
|
||||
|
||||
if(operation === 'getAll'){
|
||||
} else if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
if(resource === 'contact'){
|
||||
|
||||
if (resource === 'contact') {
|
||||
if (returnAll) {
|
||||
const endpoint = 'api/contacts';
|
||||
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
|
||||
|
@ -139,17 +134,15 @@ export class AgileCrm implements INodeType {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(operation === 'create'){
|
||||
} else if (operation === 'create') {
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
const body: IContact = {};
|
||||
const properties : IDataObject[] = [];
|
||||
const properties: IDataObject[] = [];
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '' ) {
|
||||
if (additionalFieldsJson !== '') {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
|
@ -165,7 +158,7 @@ export class AgileCrm implements INodeType {
|
|||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
// if company, add 'company' as type. default is person
|
||||
if(resource === 'company'){
|
||||
if (resource === 'company') {
|
||||
body.type = 'COMPANY';
|
||||
}
|
||||
if (additionalFields.starValue) {
|
||||
|
@ -176,36 +169,36 @@ export class AgileCrm implements INodeType {
|
|||
}
|
||||
|
||||
// Contact specific properties
|
||||
if(resource === 'contact'){
|
||||
if(additionalFields.firstName){
|
||||
if (resource === 'contact') {
|
||||
if (additionalFields.firstName) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'first_name',
|
||||
value: additionalFields.firstName as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.lastName){
|
||||
if (additionalFields.lastName) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'last_name',
|
||||
value: additionalFields.lastName as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.company){
|
||||
if (additionalFields.company) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'company',
|
||||
value: additionalFields.company as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.title){
|
||||
if (additionalFields.title) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'title',
|
||||
value: additionalFields.title as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.emailOptions){
|
||||
if (additionalFields.emailOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.emailOptions.emailProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -216,7 +209,7 @@ export class AgileCrm implements INodeType {
|
|||
} as IDataObject);
|
||||
});
|
||||
}
|
||||
if(additionalFields.addressOptions){
|
||||
if (additionalFields.addressOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.addressOptions.addressProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -228,7 +221,7 @@ export class AgileCrm implements INodeType {
|
|||
});
|
||||
}
|
||||
|
||||
if(additionalFields.phoneOptions){
|
||||
if (additionalFields.phoneOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.phoneOptions.phoneProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -240,7 +233,7 @@ export class AgileCrm implements INodeType {
|
|||
});
|
||||
}
|
||||
} else if (resource === 'company') {
|
||||
if(additionalFields.email){
|
||||
if (additionalFields.email) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'email',
|
||||
|
@ -248,7 +241,7 @@ export class AgileCrm implements INodeType {
|
|||
} as IDataObject);
|
||||
}
|
||||
|
||||
if(additionalFields.address){
|
||||
if (additionalFields.address) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'address',
|
||||
|
@ -256,7 +249,7 @@ export class AgileCrm implements INodeType {
|
|||
} as IDataObject);
|
||||
}
|
||||
|
||||
if(additionalFields.phone){
|
||||
if (additionalFields.phone) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'phone',
|
||||
|
@ -266,7 +259,7 @@ export class AgileCrm implements INodeType {
|
|||
|
||||
}
|
||||
|
||||
if(additionalFields.websiteOptions){
|
||||
if (additionalFields.websiteOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.websiteOptions.websiteProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -278,7 +271,7 @@ export class AgileCrm implements INodeType {
|
|||
});
|
||||
}
|
||||
|
||||
if(additionalFields.customProperties){
|
||||
if (additionalFields.customProperties) {
|
||||
//@ts-ignore
|
||||
additionalFields.customProperties.customProperty.map(property => {
|
||||
properties.push({
|
||||
|
@ -294,19 +287,18 @@ export class AgileCrm implements INodeType {
|
|||
}
|
||||
const endpoint = 'api/contacts';
|
||||
responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, body);
|
||||
}
|
||||
|
||||
if(operation === 'update') {
|
||||
} else if (operation === 'update') {
|
||||
const contactId = this.getNodeParameter(idGetter, i) as string;
|
||||
const contactUpdatePayload : IContactUpdate = {id: contactId};
|
||||
const contactUpdatePayload: IContactUpdate = { id: contactId };
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
const body: IContact = {};
|
||||
const properties : IDataObject[] = [];
|
||||
const properties: IDataObject[] = [];
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '' ) {
|
||||
if (additionalFieldsJson !== '') {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
|
@ -327,41 +319,41 @@ export class AgileCrm implements INodeType {
|
|||
}
|
||||
|
||||
// Contact specific properties
|
||||
if(resource === 'contact'){
|
||||
if (resource === 'contact') {
|
||||
|
||||
if (additionalFields.leadScore) {
|
||||
body.lead_score = additionalFields.leadScore as string;
|
||||
}
|
||||
|
||||
if(additionalFields.firstName){
|
||||
|
||||
if (additionalFields.firstName) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'first_name',
|
||||
value: additionalFields.firstName as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.lastName){
|
||||
if (additionalFields.lastName) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'last_name',
|
||||
value: additionalFields.lastName as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.company){
|
||||
if (additionalFields.company) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'company',
|
||||
value: additionalFields.company as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.title){
|
||||
if (additionalFields.title) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'title',
|
||||
value: additionalFields.title as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.emailOptions){
|
||||
if (additionalFields.emailOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.emailOptions.emailProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -372,7 +364,7 @@ export class AgileCrm implements INodeType {
|
|||
} as IDataObject);
|
||||
});
|
||||
}
|
||||
if(additionalFields.addressOptions){
|
||||
if (additionalFields.addressOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.addressOptions.addressProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -384,7 +376,7 @@ export class AgileCrm implements INodeType {
|
|||
});
|
||||
}
|
||||
|
||||
if(additionalFields.phoneOptions){
|
||||
if (additionalFields.phoneOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.phoneOptions.phoneProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -396,7 +388,7 @@ export class AgileCrm implements INodeType {
|
|||
});
|
||||
}
|
||||
} else if (resource === 'company') {
|
||||
if(additionalFields.email){
|
||||
if (additionalFields.email) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'email',
|
||||
|
@ -404,7 +396,7 @@ export class AgileCrm implements INodeType {
|
|||
} as IDataObject);
|
||||
}
|
||||
|
||||
if(additionalFields.address){
|
||||
if (additionalFields.address) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'address',
|
||||
|
@ -412,7 +404,7 @@ export class AgileCrm implements INodeType {
|
|||
} as IDataObject);
|
||||
}
|
||||
|
||||
if(additionalFields.phone){
|
||||
if (additionalFields.phone) {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'phone',
|
||||
|
@ -422,7 +414,7 @@ export class AgileCrm implements INodeType {
|
|||
|
||||
}
|
||||
|
||||
if(additionalFields.websiteOptions){
|
||||
if (additionalFields.websiteOptions) {
|
||||
//@ts-ignore
|
||||
additionalFields.websiteOptions.websiteProperties.map(property => {
|
||||
properties.push({
|
||||
|
@ -433,7 +425,7 @@ export class AgileCrm implements INodeType {
|
|||
} as IDataObject);
|
||||
});
|
||||
}
|
||||
if(additionalFields.customProperties){
|
||||
if (additionalFields.customProperties) {
|
||||
//@ts-ignore
|
||||
additionalFields.customProperties.customProperty.map(property => {
|
||||
properties.push({
|
||||
|
@ -453,26 +445,23 @@ export class AgileCrm implements INodeType {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
if(resource === 'deal'){
|
||||
} else if (resource === 'deal') {
|
||||
|
||||
if(operation === 'get'){
|
||||
if (operation === 'get') {
|
||||
const dealId = this.getNodeParameter('dealId', i) as string;
|
||||
|
||||
const endpoint = `api/opportunity/${dealId}`;
|
||||
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
|
||||
}
|
||||
|
||||
if(operation === 'delete'){
|
||||
} else if (operation === 'delete') {
|
||||
const contactId = this.getNodeParameter('dealId', i) as string;
|
||||
|
||||
const endpoint = `api/opportunity/${contactId}`;
|
||||
responseData = await agileCrmApiRequest.call(this, 'DELETE', endpoint, {});
|
||||
}
|
||||
|
||||
if(operation === 'getAll'){
|
||||
} else if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
|
||||
if (returnAll) {
|
||||
const endpoint = 'api/opportunity';
|
||||
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
|
||||
|
@ -481,9 +470,8 @@ export class AgileCrm implements INodeType {
|
|||
const endpoint = `api/opportunity?page_size=${limit}`;
|
||||
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
|
||||
}
|
||||
}
|
||||
|
||||
if(operation === 'create'){
|
||||
} else if (operation === 'create') {
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
const body: IDeal = {};
|
||||
|
@ -491,12 +479,9 @@ export class AgileCrm implements INodeType {
|
|||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '' ) {
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
|
||||
} else {
|
||||
throw new Error('Additional fields must be a valid JSON');
|
||||
}
|
||||
|
@ -504,18 +489,18 @@ export class AgileCrm implements INodeType {
|
|||
|
||||
} else {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
|
||||
body.close_date = new Date(this.getNodeParameter('closeDate', i) as string).getTime();
|
||||
body.expected_value = this.getNodeParameter('expectedValue', i) as number;
|
||||
body.milestone = this.getNodeParameter('milestone', i) as string;
|
||||
body.probability = this.getNodeParameter('probability', i) as number;
|
||||
body.name = this.getNodeParameter('name', i) as string;
|
||||
|
||||
if(additionalFields.contactIds){
|
||||
if (additionalFields.contactIds) {
|
||||
body.contactIds = additionalFields.contactIds as string[];
|
||||
}
|
||||
|
||||
if(additionalFields.customData){
|
||||
if (additionalFields.customData) {
|
||||
// @ts-ignore
|
||||
body.customData = additionalFields.customData.customProperty as IDealCustomProperty[];
|
||||
}
|
||||
|
@ -524,9 +509,8 @@ export class AgileCrm implements INodeType {
|
|||
|
||||
const endpoint = 'api/opportunity';
|
||||
responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, body);
|
||||
}
|
||||
|
||||
if(operation === 'update'){
|
||||
} else if (operation === 'update') {
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
const body: IDeal = {};
|
||||
|
@ -534,14 +518,14 @@ export class AgileCrm implements INodeType {
|
|||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '' ) {
|
||||
if (additionalFieldsJson !== '') {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
|
||||
} else {
|
||||
throw new Error('Additional fields must be a valid JSON');
|
||||
throw new Error('Additional fields must be valid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -549,23 +533,23 @@ export class AgileCrm implements INodeType {
|
|||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
body.id = this.getNodeParameter('dealId', i) as number;
|
||||
|
||||
if(additionalFields.expectedValue){
|
||||
if (additionalFields.expectedValue) {
|
||||
body.expected_value = additionalFields.expectedValue as number;
|
||||
}
|
||||
|
||||
if(additionalFields.name){
|
||||
if (additionalFields.name) {
|
||||
body.name = additionalFields.name as string;
|
||||
}
|
||||
|
||||
if(additionalFields.probability){
|
||||
if (additionalFields.probability) {
|
||||
body.probability = additionalFields.probability as number;
|
||||
}
|
||||
|
||||
if(additionalFields.contactIds){
|
||||
if (additionalFields.contactIds) {
|
||||
body.contactIds = additionalFields.contactIds as string[];
|
||||
}
|
||||
|
||||
if(additionalFields.customData){
|
||||
if (additionalFields.customData) {
|
||||
// @ts-ignore
|
||||
body.customData = additionalFields.customData.customProperty as IDealCustomProperty[];
|
||||
}
|
||||
|
@ -577,7 +561,6 @@ export class AgileCrm implements INodeType {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
|
@ -588,5 +571,5 @@ export class AgileCrm implements INodeType {
|
|||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -45,11 +45,11 @@ export const companyOperations = [
|
|||
},
|
||||
] as INodeProperties[];
|
||||
export const companyFields = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* company:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* company:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'company ID',
|
||||
displayName: 'Company ID',
|
||||
name: 'companyId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
|
@ -66,7 +66,7 @@ export const companyFields = [
|
|||
default: '',
|
||||
description: 'Unique identifier for a particular company',
|
||||
},
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* company:get all */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -147,7 +147,6 @@ export const companyFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
|
||||
description: 'Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-companys---companies-api" target="_blank">here</a>.',
|
||||
},
|
||||
{
|
||||
|
@ -174,18 +173,14 @@ export const companyFields = [
|
|||
displayName: 'Address',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
|
||||
default: '',
|
||||
placeholder: 'Company address',
|
||||
description: 'Company address.',
|
||||
},
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
|
||||
default: '',
|
||||
placeholder: 'Company email',
|
||||
description: 'Company email.',
|
||||
},
|
||||
{
|
||||
|
@ -193,16 +188,13 @@ export const companyFields = [
|
|||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'Company name',
|
||||
description: 'Company name.',
|
||||
},
|
||||
{
|
||||
displayName: 'Phone',
|
||||
name: 'phone',
|
||||
type: 'string',
|
||||
|
||||
default: '',
|
||||
placeholder: 'Company phone',
|
||||
description: 'Company phone.',
|
||||
},
|
||||
{
|
||||
|
@ -247,14 +239,12 @@ export const companyFields = [
|
|||
multipleValueButtonText: 'Add Tag',
|
||||
},
|
||||
default: [],
|
||||
placeholder: 'Tag',
|
||||
description: 'Unique identifiers added to company, for easy management of companys. This is not applicable for companies.',
|
||||
},
|
||||
{
|
||||
displayName: 'Website',
|
||||
name: 'websiteOptions',
|
||||
type: 'fixedCollection',
|
||||
|
||||
description: 'Companies websites.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
|
@ -273,35 +263,35 @@ export const companyFields = [
|
|||
description: 'Type of website.',
|
||||
options: [
|
||||
{
|
||||
name: 'FACEBOOK',
|
||||
name: 'Facebook',
|
||||
value: 'facebook',
|
||||
},
|
||||
{
|
||||
name: 'FEED',
|
||||
name: 'Feed',
|
||||
value: 'feed',
|
||||
},
|
||||
{
|
||||
name: 'FLICKR',
|
||||
name: 'Flickr',
|
||||
value: 'flickr',
|
||||
},
|
||||
{
|
||||
name: 'LINKEDIN',
|
||||
value: 'linkedin',
|
||||
},
|
||||
{
|
||||
name: 'GITHUB',
|
||||
name: 'Github',
|
||||
value: 'github',
|
||||
},
|
||||
{
|
||||
name: 'GOOGLE_PLUS',
|
||||
name: 'Google Plus',
|
||||
value: 'googlePlus',
|
||||
},
|
||||
{
|
||||
name: 'SKYPE',
|
||||
name: 'LinkedIn',
|
||||
value: 'linkedin',
|
||||
},
|
||||
{
|
||||
name: 'Skype',
|
||||
value: 'skype',
|
||||
},
|
||||
{
|
||||
name: 'TWITTER',
|
||||
name: 'Twitter',
|
||||
value: 'twitter',
|
||||
},
|
||||
{
|
||||
|
@ -309,14 +299,14 @@ export const companyFields = [
|
|||
value: 'url',
|
||||
},
|
||||
{
|
||||
name: 'XING',
|
||||
name: 'Xing',
|
||||
value: 'xing',
|
||||
},
|
||||
{
|
||||
name: 'YOUTUBE',
|
||||
name: 'YouTube',
|
||||
value: 'youtube',
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'URL',
|
||||
|
@ -324,19 +314,16 @@ export const companyFields = [
|
|||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
|
||||
description: 'Website URL',
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Properties',
|
||||
name: 'customProperties',
|
||||
type: 'fixedCollection',
|
||||
|
||||
description: 'Custom Properties',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
|
@ -352,33 +339,29 @@ export const companyFields = [
|
|||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
|
||||
description: 'Property name.'
|
||||
},
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
name: 'subtype',
|
||||
type: 'string',
|
||||
|
||||
default: '',
|
||||
|
||||
description: 'Property sub type.',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
|
||||
default: '',
|
||||
|
||||
description: 'Property value.',
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* company:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -400,11 +383,12 @@ export const companyFields = [
|
|||
default: '',
|
||||
description: 'ID of company to delete',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* company:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'company ID',
|
||||
displayName: 'Company ID',
|
||||
name: 'companyId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
|
@ -459,7 +443,6 @@ export const companyFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
|
||||
description: 'Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-companys---companies-api" target="_blank">here</a>.',
|
||||
},
|
||||
{
|
||||
|
@ -487,7 +470,6 @@ export const companyFields = [
|
|||
name: 'email',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'Company address',
|
||||
description: 'Company address.',
|
||||
},
|
||||
{
|
||||
|
@ -495,7 +477,6 @@ export const companyFields = [
|
|||
name: 'email',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'Company email',
|
||||
description: 'Company email.',
|
||||
},
|
||||
{
|
||||
|
@ -507,29 +488,29 @@ export const companyFields = [
|
|||
options: [
|
||||
{
|
||||
name: '0',
|
||||
value: 0
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
name: '1',
|
||||
value: 1
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: '2',
|
||||
value: 2
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
name: '3',
|
||||
value: 3
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
name: '4',
|
||||
value: 4
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
name: '5',
|
||||
value: 5
|
||||
value: 5,
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Tags',
|
||||
|
@ -540,7 +521,6 @@ export const companyFields = [
|
|||
multipleValueButtonText: 'Add Tag',
|
||||
},
|
||||
default: [],
|
||||
placeholder: 'Tag',
|
||||
description: 'Unique identifiers added to company, for easy management of companys. This is not applicable for companies.',
|
||||
},
|
||||
{
|
||||
|
@ -548,7 +528,6 @@ export const companyFields = [
|
|||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'Company name',
|
||||
description: 'Company name.',
|
||||
},
|
||||
{
|
||||
|
@ -556,14 +535,13 @@ export const companyFields = [
|
|||
name: 'phone',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'Company phone',
|
||||
description: 'Company phone.',
|
||||
},
|
||||
{
|
||||
displayName: 'Website',
|
||||
name: 'websiteOptions',
|
||||
type: 'fixedCollection',
|
||||
description: 'companys websites.',
|
||||
description: 'Companys websites.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
|
@ -581,35 +559,35 @@ export const companyFields = [
|
|||
description: 'Type of website.',
|
||||
options: [
|
||||
{
|
||||
name: 'FACEBOOK',
|
||||
name: 'Facebook',
|
||||
value: 'facebook',
|
||||
},
|
||||
{
|
||||
name: 'FEED',
|
||||
name: 'Feed',
|
||||
value: 'feed',
|
||||
},
|
||||
{
|
||||
name: 'FLICKR',
|
||||
name: 'Flickr',
|
||||
value: 'flickr',
|
||||
},
|
||||
{
|
||||
name: 'LINKEDIN',
|
||||
value: 'linkedin',
|
||||
},
|
||||
{
|
||||
name: 'GITHUB',
|
||||
name: 'Github',
|
||||
value: 'github',
|
||||
},
|
||||
{
|
||||
name: 'GOOGLE_PLUS',
|
||||
name: 'Google Plus',
|
||||
value: 'googlePlus',
|
||||
},
|
||||
{
|
||||
name: 'SKYPE',
|
||||
name: 'LinkedIn',
|
||||
value: 'linkedin',
|
||||
},
|
||||
{
|
||||
name: 'Skype',
|
||||
value: 'skype',
|
||||
},
|
||||
{
|
||||
name: 'TWITTER',
|
||||
name: 'Twitter',
|
||||
value: 'twitter',
|
||||
},
|
||||
{
|
||||
|
@ -617,14 +595,14 @@ export const companyFields = [
|
|||
value: 'url',
|
||||
},
|
||||
{
|
||||
name: 'XING',
|
||||
name: 'Xing',
|
||||
value: 'xing',
|
||||
},
|
||||
{
|
||||
name: 'YOUTUBE',
|
||||
name: 'YouTube',
|
||||
value: 'youtube',
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'URL',
|
||||
|
@ -633,10 +611,10 @@ export const companyFields = [
|
|||
required: true,
|
||||
default: '',
|
||||
description: 'Website URL',
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Properties',
|
||||
|
@ -657,7 +635,7 @@ export const companyFields = [
|
|||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Property name.'
|
||||
description: 'Property name.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
|
@ -672,10 +650,9 @@ export const companyFields = [
|
|||
type: 'string',
|
||||
default: '',
|
||||
description: 'Property value.',
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
],
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,27 +1,26 @@
|
|||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export interface IProperty {
|
||||
type: string;
|
||||
name: string;
|
||||
subtype?: string;
|
||||
value?: string;
|
||||
export interface IProperty {
|
||||
type: string;
|
||||
name: string;
|
||||
subtype?: string;
|
||||
value?: string;
|
||||
}
|
||||
|
||||
export interface IContact {
|
||||
type?: string;
|
||||
star_value?: string;
|
||||
lead_score?: string;
|
||||
tags?: string[];
|
||||
properties?: IDataObject[];
|
||||
}
|
||||
|
||||
export interface IContactUpdate {
|
||||
id: string;
|
||||
properties?: IDataObject[];
|
||||
star_value?: string;
|
||||
lead_score?: string;
|
||||
tags?: string[];
|
||||
}
|
||||
export interface IContact {
|
||||
type?: string;
|
||||
star_value?: string;
|
||||
lead_score?: string;
|
||||
tags?: string[];
|
||||
properties?: IDataObject[];
|
||||
}
|
||||
|
||||
export interface IContactUpdate {
|
||||
id: string;
|
||||
properties?: IDataObject[];
|
||||
star_value?: string;
|
||||
lead_score?: string;
|
||||
tags?: string[];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const dealOperations = [
|
||||
{
|
||||
|
@ -15,12 +15,12 @@ export const dealOperations = [
|
|||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a new deal',
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a deal',
|
||||
|
@ -48,9 +48,9 @@ export const dealOperations = [
|
|||
] as INodeProperties[];
|
||||
|
||||
export const dealFields = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Deal ID',
|
||||
name: 'dealId',
|
||||
|
@ -69,455 +69,447 @@ export const dealFields = [
|
|||
default: '',
|
||||
description: 'Unique identifier for a particular deal',
|
||||
},
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:get all */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 20,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'If all results should be returned or only up to a given limit.',
|
||||
},
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Close Date',
|
||||
name: 'closeDate',
|
||||
type: 'dateTime',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Closing date of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Expected Value',
|
||||
name: 'expectedValue',
|
||||
type: 'number',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 1000000000000
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 1,
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Milestone',
|
||||
name: 'milestone',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Milestone of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Name of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Probability',
|
||||
name: 'probability',
|
||||
type: 'number',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 50,
|
||||
description: 'Expected probability.',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: ' Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-deals---companies-api" target="_blank">here</a>.`,
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Contact Ids',
|
||||
name: 'contactIds',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
multipleValueButtonText: 'Add ID',
|
||||
},
|
||||
default: [],
|
||||
placeholder: 'ID',
|
||||
description: 'Unique contact identifiers.',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Data',
|
||||
name: 'customData',
|
||||
type: 'fixedCollection',
|
||||
|
||||
description: 'Custom Data',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Property',
|
||||
name: 'customProperty',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
description: 'Property name.'
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: "",
|
||||
description: 'Property value.',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:get all */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 20,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'If all results should be returned or only up to a given limit.',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Deal ID',
|
||||
name: 'dealId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of deal to delete',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Deal ID',
|
||||
name: 'dealId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Id of deal to update',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-deals---companies-api" target="_blank">here</a>.`,
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Expected Value',
|
||||
name: 'expectedValue',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 10000
|
||||
},
|
||||
default: '',
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Probability',
|
||||
name: 'probability',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100
|
||||
},
|
||||
default: 50,
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Contact Ids',
|
||||
name: 'contactIds',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
multipleValueButtonText: 'Add ID',
|
||||
},
|
||||
default: [],
|
||||
placeholder: 'ID',
|
||||
description: 'Unique contact identifiers.',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Data',
|
||||
name: 'customData',
|
||||
type: 'fixedCollection',
|
||||
description: 'Custom Data',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Property',
|
||||
name: 'customProperty',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
description: 'Property name.'
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: "",
|
||||
description: 'Property value.',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Close Date',
|
||||
name: 'closeDate',
|
||||
type: 'dateTime',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Closing date of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Expected Value',
|
||||
name: 'expectedValue',
|
||||
type: 'number',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 1000000000000
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 1,
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Milestone',
|
||||
name: 'milestone',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Milestone of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Name of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Probability',
|
||||
name: 'probability',
|
||||
type: 'number',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 50,
|
||||
description: 'Expected probability.',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: ' Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-deals---companies-api" target="_blank">here</a>.`,
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Contact Ids',
|
||||
name: 'contactIds',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
multipleValueButtonText: 'Add ID',
|
||||
},
|
||||
default: [],
|
||||
description: 'Unique contact identifiers.',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Data',
|
||||
name: 'customData',
|
||||
type: 'fixedCollection',
|
||||
description: 'Custom Data',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Property',
|
||||
name: 'customProperty',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Property name.'
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Property value.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Deal ID',
|
||||
name: 'dealId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of deal to delete',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Deal ID',
|
||||
name: 'dealId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Id of deal to update',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-deals---companies-api" target="_blank">here</a>.`,
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Expected Value',
|
||||
name: 'expectedValue',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 10000
|
||||
},
|
||||
default: '',
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Probability',
|
||||
name: 'probability',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100
|
||||
},
|
||||
default: 50,
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Contact Ids',
|
||||
name: 'contactIds',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
multipleValueButtonText: 'Add ID',
|
||||
},
|
||||
default: [],
|
||||
description: 'Unique contact identifiers.',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Data',
|
||||
name: 'customData',
|
||||
type: 'fixedCollection',
|
||||
description: 'Custom Data',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Property',
|
||||
name: 'customProperty',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Property name.'
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Property value.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
export interface IDealCustomProperty {
|
||||
name: string;
|
||||
value: string;
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface IDeal {
|
||||
id?: number;
|
||||
expected_value?: number;
|
||||
probability?: number;
|
||||
name?: string;
|
||||
close_date?: number;
|
||||
milestone?: string;
|
||||
contactIds?: string[];
|
||||
customData?: IDealCustomProperty[];
|
||||
}
|
||||
id?: number;
|
||||
expected_value?: number;
|
||||
probability?: number;
|
||||
name?: string;
|
||||
close_date?: number;
|
||||
milestone?: string;
|
||||
contactIds?: string[];
|
||||
customData?: IDealCustomProperty[];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
OptionsWithUri
|
||||
} from 'request';
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
|
@ -12,81 +12,74 @@ import {
|
|||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
import { IContactUpdate, IProperty } from './ContactInterface';
|
||||
import { IContactUpdate } from './ContactInterface';
|
||||
|
||||
|
||||
export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> {
|
||||
export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const credentials = this.getCredentials('agileCrmApi');
|
||||
const credentials = this.getCredentials('agileCrmApi');
|
||||
const options: OptionsWithUri = {
|
||||
method,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
auth: {
|
||||
auth: {
|
||||
username: credentials!.email as string,
|
||||
password: credentials!.apiKey as string
|
||||
},
|
||||
uri: uri || `https://n8nio.agilecrm.com/dev/${endpoint}`,
|
||||
json: true
|
||||
json: true,
|
||||
};
|
||||
|
||||
// Only add Body property if method not GET or DELETE to avoid 400 response
|
||||
if(method !== "GET" && method !== "DELETE"){
|
||||
if (method !== 'GET' && method !== 'DELETE') {
|
||||
options.body = body;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
|
||||
if (error.response && error.response.body && error.response.body.errors) {
|
||||
const errorMessages = error.response.body.errors.map((e: IDataObject) => e.message);
|
||||
throw new Error(`AgileCRM error response [${error.statusCode}]: ${errorMessages.join(' | ')}`);
|
||||
}
|
||||
|
||||
throw error;
|
||||
throw new Error(`AgileCRM error response: ${error.message}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method = 'PUT', endpoint?: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> {
|
||||
export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method = 'PUT', endpoint?: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
const baseUri = 'https://n8nio.agilecrm.com/dev/';
|
||||
const credentials = this.getCredentials('agileCrmApi');
|
||||
const credentials = this.getCredentials('agileCrmApi');
|
||||
const options: OptionsWithUri = {
|
||||
method,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: {id: body.id},
|
||||
auth: {
|
||||
body: { id: body.id },
|
||||
auth: {
|
||||
username: credentials!.email as string,
|
||||
password: credentials!.apiKey as string
|
||||
password: credentials!.apiKey as string,
|
||||
},
|
||||
uri: uri || baseUri,
|
||||
json: true
|
||||
json: true,
|
||||
};
|
||||
|
||||
const successfulUpdates = [];
|
||||
let lastSuccesfulUpdateReturn : any;
|
||||
const payload : IContactUpdate = body;
|
||||
|
||||
const successfulUpdates = [];
|
||||
let lastSuccesfulUpdateReturn: any; // tslint:disable-line:no-any
|
||||
const payload: IContactUpdate = body;
|
||||
|
||||
try {
|
||||
// Due to API, we must update each property separately. For user it looks like one seamless update
|
||||
if(payload.properties){
|
||||
if (payload.properties) {
|
||||
options.body.properties = payload.properties;
|
||||
options.uri = baseUri + 'api/contacts/edit-properties';
|
||||
lastSuccesfulUpdateReturn = await this.helpers.request!(options);
|
||||
|
||||
// Iterate trough properties and show them as individial updates instead of only vague "properties"
|
||||
payload.properties?.map((property : any) => {
|
||||
successfulUpdates.push(`${property.name} `);
|
||||
payload.properties?.map((property: any) => { // tslint:disable-line:no-any
|
||||
successfulUpdates.push(`${property.name}`);
|
||||
});
|
||||
|
||||
delete options.body.properties;
|
||||
}
|
||||
if(payload.lead_score){
|
||||
if (payload.lead_score) {
|
||||
options.body.lead_score = payload.lead_score;
|
||||
options.uri = baseUri + 'api/contacts/edit/lead-score';
|
||||
lastSuccesfulUpdateReturn = await this.helpers.request!(options);
|
||||
|
@ -95,18 +88,18 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu
|
|||
|
||||
delete options.body.lead_score;
|
||||
}
|
||||
if(body.tags){
|
||||
if (body.tags) {
|
||||
options.body.tags = payload.tags;
|
||||
options.uri = baseUri + 'api/contacts/edit/tags';
|
||||
lastSuccesfulUpdateReturn = await this.helpers.request!(options);
|
||||
|
||||
payload.tags?.map((tag : string) => {
|
||||
successfulUpdates.push(`(Tag) ${tag} `);
|
||||
payload.tags?.map((tag: string) => {
|
||||
successfulUpdates.push(`(Tag) ${tag}`);
|
||||
});
|
||||
|
||||
delete options.body.tags;
|
||||
}
|
||||
if(body.star_value){
|
||||
if (body.star_value) {
|
||||
options.body.star_value = payload.star_value;
|
||||
options.uri = baseUri + 'api/contacts/edit/add-star';
|
||||
lastSuccesfulUpdateReturn = await this.helpers.request!(options);
|
||||
|
@ -119,13 +112,11 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu
|
|||
return lastSuccesfulUpdateReturn;
|
||||
|
||||
} catch (error) {
|
||||
|
||||
if (error.response && error.response.body && error.response.body.errors) {
|
||||
const errorMessages = error.response.body.errors.map((e: IDataObject) => e.message);
|
||||
throw new Error(`AgileCRM error response [${error.statusCode}]: ${errorMessages.join(' | ')}`);
|
||||
if (successfulUpdates.length === 0) {
|
||||
throw new Error(`AgileCRM error response: ${error.message}`);
|
||||
} else {
|
||||
throw new Error(`Not all properties updated. Updated properties: ${successfulUpdates.join(', ')} \n \nAgileCRM error response: ${error.message}`);
|
||||
}
|
||||
|
||||
throw new Error(`Not all items updated. Updated items: ${successfulUpdates.join(' , ')} \n \n` + error);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -139,4 +130,3 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in a new issue