mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
Simplified field insertion for users, added all create contact functionality
This commit is contained in:
parent
aca8441164
commit
93efb17c10
|
@ -96,6 +96,7 @@ export class AgileCrm implements INodeType {
|
|||
if(operation === 'create'){
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
const body: IContact = {};
|
||||
let properties : IDataObject[] = [];
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
@ -124,12 +125,93 @@ export class AgileCrm implements INodeType {
|
|||
if (additionalFields.tags) {
|
||||
body.tags = additionalFields.tags as string[];
|
||||
}
|
||||
if (additionalFields.properties) {
|
||||
body.properties = (additionalFields.properties as IDataObject).property as IDataObject[];
|
||||
if(additionalFields.firstName){
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'first_name',
|
||||
value: additionalFields.firstName as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.lastName){
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'last_name',
|
||||
value: additionalFields.lastName as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.company){
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'company',
|
||||
value: additionalFields.company as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.title){
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
name: 'title',
|
||||
value: additionalFields.title as string
|
||||
} as IDataObject);
|
||||
}
|
||||
if(additionalFields.emailOptions){
|
||||
//@ts-ignore
|
||||
additionalFields.emailOptions.emailProperties.map(property => {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
subtype: property.subtype as string,
|
||||
name: 'email',
|
||||
value: property.email as string
|
||||
} as IDataObject);
|
||||
})
|
||||
}
|
||||
if(additionalFields.addressOptions){
|
||||
//@ts-ignore
|
||||
additionalFields.addressOptions.addressProperties.map(property => {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
subtype: property.subtype as string,
|
||||
name: 'address',
|
||||
value: property.address as string
|
||||
} as IDataObject);
|
||||
})
|
||||
}
|
||||
if(additionalFields.websiteOptions){
|
||||
//@ts-ignore
|
||||
additionalFields.websiteOptions.websiteProperties.map(property => {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
subtype: property.subtype as string,
|
||||
name: 'webiste',
|
||||
value: property.url as string
|
||||
} as IDataObject);
|
||||
})
|
||||
}
|
||||
if(additionalFields.phoneOptions){
|
||||
//@ts-ignore
|
||||
additionalFields.phoneOptions.phoneProperties.map(property => {
|
||||
properties.push({
|
||||
type: 'SYSTEM',
|
||||
subtype: property.subtype as string,
|
||||
name: 'phone',
|
||||
value: property.number as string
|
||||
} as IDataObject);
|
||||
})
|
||||
}
|
||||
if(additionalFields.customProperties){
|
||||
//@ts-ignore
|
||||
additionalFields.customProperties.customProperty.map(property => {
|
||||
properties.push({
|
||||
type: 'CUSTOM',
|
||||
subtype: property.subtype as string,
|
||||
name: property.name,
|
||||
value: property.value as string
|
||||
} as IDataObject);
|
||||
})
|
||||
}
|
||||
body.properties = properties;
|
||||
|
||||
}
|
||||
const endpoint = 'api/contacts';
|
||||
console.log(body);
|
||||
responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, body);
|
||||
}
|
||||
|
||||
|
|
|
@ -223,174 +223,162 @@ export const contactFields = [
|
|||
description: 'Unique identifiers added to contact, for easy management of contacts. This is not applicable for companies.',
|
||||
},
|
||||
{
|
||||
displayName: 'Properties',
|
||||
name: 'properties',
|
||||
displayName: 'First Name',
|
||||
name: 'firstName',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: "",
|
||||
placeholder: 'First Name',
|
||||
description: 'Contact first name.',
|
||||
},
|
||||
{
|
||||
displayName: 'Last Name',
|
||||
name: 'lastName',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: "",
|
||||
placeholder: 'Last Name',
|
||||
description: 'Contact last name.',
|
||||
},
|
||||
{
|
||||
displayName: 'Company',
|
||||
name: 'company',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: "",
|
||||
placeholder: 'Company',
|
||||
description: 'Company Name.',
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: "",
|
||||
placeholder: 'Title',
|
||||
description: 'Professional title.',
|
||||
},
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'emailOptions',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
description: 'Contact properties are represented by list of JSON objects, each JSON object should follow the prototype shown. Custom fields will have type as CUSTOM and others will have type as SYSTEM.',
|
||||
required: true,
|
||||
required: false,
|
||||
description: 'Contact email.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Property',
|
||||
name: 'property',
|
||||
displayName: 'Email Properties',
|
||||
name: 'emailProperties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
name: 'subtype',
|
||||
type: 'options',
|
||||
default: 'SYSTEM',
|
||||
required: true,
|
||||
description: 'Type of the field.',
|
||||
options: [
|
||||
{
|
||||
name: 'SYSTEM',
|
||||
value: 'SYSTEM',
|
||||
},
|
||||
{
|
||||
name: 'CUSTOM',
|
||||
value: 'CUSTOM'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'Name of the field.'
|
||||
},
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
name: 'subType',
|
||||
default: '',
|
||||
required: false,
|
||||
type: 'options',
|
||||
description: 'Name of the field.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: [
|
||||
'SYSTEM'
|
||||
],
|
||||
name: [
|
||||
'email'
|
||||
]
|
||||
}
|
||||
},
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Type of Email',
|
||||
options: [
|
||||
{
|
||||
name: 'Work',
|
||||
value: 'work',
|
||||
|
||||
value: 'work'
|
||||
},
|
||||
{
|
||||
name: 'Personal',
|
||||
value: 'personal',
|
||||
|
||||
value: 'personal'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
name: 'subType',
|
||||
default: '',
|
||||
required: false,
|
||||
type: 'options',
|
||||
description: 'Name of the field.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: [
|
||||
'SYSTEM'
|
||||
],
|
||||
name: [
|
||||
'phone'
|
||||
]
|
||||
}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Work',
|
||||
value: 'work',
|
||||
|
||||
},
|
||||
{
|
||||
name: 'Home',
|
||||
value: 'home',
|
||||
},
|
||||
{
|
||||
name: 'Mobile',
|
||||
value: 'mobile',
|
||||
},
|
||||
{
|
||||
name: 'Main',
|
||||
value: 'main',
|
||||
},
|
||||
{
|
||||
name: 'Home Fax',
|
||||
value: 'homeFax',
|
||||
},
|
||||
{
|
||||
name: 'Work Fax',
|
||||
value: 'workFax',
|
||||
},
|
||||
{
|
||||
name: 'Other',
|
||||
value: 'other',
|
||||
},
|
||||
]
|
||||
},
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Email',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Address',
|
||||
name: 'addressOptions',
|
||||
type: 'fixedCollection',
|
||||
required: false,
|
||||
description: 'Contacts address.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Address Properties',
|
||||
name: 'addressProperties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
name: 'subType',
|
||||
default: '',
|
||||
required: false,
|
||||
displayName: 'Type',
|
||||
name: 'subtype',
|
||||
type: 'options',
|
||||
description: 'Name of the field.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: [
|
||||
'SYSTEM'
|
||||
],
|
||||
name: [
|
||||
'address'
|
||||
]
|
||||
}
|
||||
},
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Type of address.',
|
||||
options: [
|
||||
{
|
||||
name: 'Home',
|
||||
value: 'home',
|
||||
value: 'home'
|
||||
},
|
||||
{
|
||||
name: 'Postal',
|
||||
value: 'postal',
|
||||
},
|
||||
value: 'postal'
|
||||
}
|
||||
,
|
||||
{
|
||||
name: 'Office',
|
||||
value: 'office',
|
||||
},
|
||||
value: 'office'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
name: 'subType',
|
||||
default: '',
|
||||
required: false,
|
||||
displayName: 'Address',
|
||||
name: 'address',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Full address.',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Website',
|
||||
name: 'websiteOptions',
|
||||
type: 'fixedCollection',
|
||||
required: false,
|
||||
description: 'Contacts websites.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Website properties.',
|
||||
name: 'websiteProperties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'subtype',
|
||||
type: 'options',
|
||||
description: 'Name of the field.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: [
|
||||
'SYSTEM'
|
||||
],
|
||||
name: [
|
||||
'website'
|
||||
]
|
||||
}
|
||||
},
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Type of website.',
|
||||
options: [
|
||||
{
|
||||
name: 'URL',
|
||||
|
@ -439,34 +427,135 @@ export const contactFields = [
|
|||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
name: 'subType',
|
||||
default: '',
|
||||
required: false,
|
||||
displayName: 'URL',
|
||||
name: 'url',
|
||||
type: 'string',
|
||||
description: 'Name of the field.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: [
|
||||
'CUSTOM'
|
||||
],
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Website URL',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Phone',
|
||||
name: 'phoneOptions',
|
||||
type: 'fixedCollection',
|
||||
required: false,
|
||||
description: 'Contacts phone.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Phone properties',
|
||||
name: 'phoneProperties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'subtype',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Type of phone number.',
|
||||
options: [
|
||||
{
|
||||
name: 'Home',
|
||||
value: 'home'
|
||||
},
|
||||
{
|
||||
name: 'Work',
|
||||
value: 'work'
|
||||
}
|
||||
}
|
||||
,
|
||||
{
|
||||
name: 'Mobile',
|
||||
value: 'mobile'
|
||||
},
|
||||
{
|
||||
name: 'Main',
|
||||
value: 'main'
|
||||
},
|
||||
{
|
||||
name: 'Home Fax',
|
||||
value: 'homeFax'
|
||||
},
|
||||
{
|
||||
name: 'Work Fax',
|
||||
value: 'workFax'
|
||||
},
|
||||
{
|
||||
name: 'Other',
|
||||
value: 'other'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Number',
|
||||
name: 'number',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Phone number.',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Properties',
|
||||
name: 'customProperties',
|
||||
type: 'fixedCollection',
|
||||
required: false,
|
||||
description: 'Custom Properties',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Property',
|
||||
name: 'customProperty',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Property name.'
|
||||
},
|
||||
{
|
||||
displayName: 'Sub Type',
|
||||
name: 'subtype',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Property sub type.',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
default: '',
|
||||
required: false,
|
||||
type: 'string',
|
||||
description: 'Value of the property.'
|
||||
},
|
||||
required: false,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Property value.',
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
},
|
||||
|
||||
|
||||
],
|
||||
},
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: object, 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> {
|
||||
|
||||
const credentials = this.getCredentials('agileCrmApi');
|
||||
const options: OptionsWithUri = {
|
||||
|
@ -34,8 +34,6 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
|
|||
if(method !== "GET"){
|
||||
options.body = body;
|
||||
}
|
||||
|
||||
console.log(options);
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
|
|
Loading…
Reference in a new issue