2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2020-04-01 15:10:41 -07:00
|
|
|
IDataObject,
|
2023-03-06 08:33:32 -08:00
|
|
|
IExecuteFunctions,
|
2020-04-01 15:10:41 -07:00
|
|
|
ILoadOptionsFunctions,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeExecutionData,
|
2020-04-01 15:10:41 -07:00
|
|
|
INodePropertyOptions,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2020-04-01 15:10:41 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { capitalCase, pascalCase } from 'change-case';
|
2022-04-08 14:32:08 -07:00
|
|
|
import moment from 'moment-timezone';
|
2022-08-17 08:50:24 -07:00
|
|
|
import { keapApiRequest, keapApiRequestAllItems, keysToSnakeCase } from './GenericFunctions';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { contactFields, contactOperations } from './ContactDescription';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { contactNoteFields, contactNoteOperations } from './ContactNoteDescription';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { contactTagFields, contactTagOperations } from './ContactTagDescription';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { ecommerceOrderFields, ecommerceOrderOperations } from './EcommerceOrderDescripion';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { ecommerceProductFields, ecommerceProductOperations } from './EcommerceProductDescription';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { emailFields, emailOperations } from './EmailDescription';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { fileFields, fileOperations } from './FileDescription';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { companyFields, companyOperations } from './CompanyDescription';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2020-04-01 15:10:41 -07:00
|
|
|
IAddress,
|
2020-10-01 05:01:39 -07:00
|
|
|
IContact,
|
2020-04-01 15:10:41 -07:00
|
|
|
IEmailContact,
|
2020-10-01 05:01:39 -07:00
|
|
|
IFax,
|
2020-04-01 15:10:41 -07:00
|
|
|
IPhone,
|
2020-10-01 05:01:39 -07:00
|
|
|
ISocialAccount,
|
2020-04-01 15:10:41 -07:00
|
|
|
} from './ConctactInterface';
|
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { IAttachment, IEmail } from './EmaiIInterface';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { INote } from './ContactNoteInterface';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { IEcommerceOrder, IItem, IShippingAddress } from './EcommerceOrderInterface';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { IEcommerceProduct } from './EcommerceProductInterface';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { IFile } from './FileInterface';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { ICompany } from './CompanyInterface';
|
2020-04-01 15:10:41 -07:00
|
|
|
|
2020-04-02 16:37:40 -07:00
|
|
|
export class Keap implements INodeType {
|
2020-04-01 15:10:41 -07:00
|
|
|
description: INodeTypeDescription = {
|
2020-04-02 16:37:40 -07:00
|
|
|
displayName: 'Keap',
|
2020-06-04 08:46:43 -07:00
|
|
|
name: 'keap',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-04-02 16:37:40 -07:00
|
|
|
icon: 'file:keap.png',
|
2020-04-01 15:10:41 -07:00
|
|
|
group: ['input'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Consume Keap API',
|
2020-04-01 15:10:41 -07:00
|
|
|
defaults: {
|
2020-04-02 16:37:40 -07:00
|
|
|
name: 'Keap',
|
2020-04-01 15:10:41 -07:00
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
2020-04-02 16:37:40 -07:00
|
|
|
name: 'keapOAuth2Api',
|
2020-04-01 15:10:41 -07:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-04-01 15:10:41 -07:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Company',
|
|
|
|
value: 'company',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Contact',
|
|
|
|
value: 'contact',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Contact Note',
|
|
|
|
value: 'contactNote',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Contact Tag',
|
|
|
|
value: 'contactTag',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Ecommerce Order',
|
|
|
|
value: 'ecommerceOrder',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Ecommerce Product',
|
|
|
|
value: 'ecommerceProduct',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Email',
|
|
|
|
value: 'email',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'File',
|
|
|
|
value: 'file',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'company',
|
|
|
|
},
|
|
|
|
// COMPANY
|
|
|
|
...companyOperations,
|
|
|
|
...companyFields,
|
|
|
|
// CONTACT
|
|
|
|
...contactOperations,
|
|
|
|
...contactFields,
|
|
|
|
// CONTACT NOTE
|
|
|
|
...contactNoteOperations,
|
|
|
|
...contactNoteFields,
|
|
|
|
// CONTACT TAG
|
|
|
|
...contactTagOperations,
|
|
|
|
...contactTagFields,
|
|
|
|
// ECOMMERCE ORDER
|
|
|
|
...ecommerceOrderOperations,
|
|
|
|
...ecommerceOrderFields,
|
|
|
|
// ECOMMERCE PRODUCT
|
|
|
|
...ecommerceProductOperations,
|
|
|
|
...ecommerceProductFields,
|
|
|
|
// EMAIL
|
|
|
|
...emailOperations,
|
|
|
|
...emailFields,
|
|
|
|
// FILE
|
|
|
|
...fileOperations,
|
|
|
|
...fileFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
2023-04-19 07:00:49 -07:00
|
|
|
// Get all the tags to display them to user so that they can
|
2020-04-01 15:10:41 -07:00
|
|
|
// select them easily
|
|
|
|
async getTags(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2020-04-02 16:37:40 -07:00
|
|
|
const tags = await keapApiRequestAllItems.call(this, 'tags', 'GET', '/tags');
|
2020-04-01 15:10:41 -07:00
|
|
|
for (const tag of tags) {
|
|
|
|
const tagName = tag.name;
|
|
|
|
const tagId = tag.id;
|
|
|
|
returnData.push({
|
|
|
|
name: tagName as string,
|
|
|
|
value: tagId as string,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2023-04-19 07:00:49 -07:00
|
|
|
// Get all the users to display them to user so that they can
|
2020-04-01 15:10:41 -07:00
|
|
|
// select them easily
|
|
|
|
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2020-04-02 16:37:40 -07:00
|
|
|
const users = await keapApiRequestAllItems.call(this, 'users', 'GET', '/users');
|
2020-04-01 15:10:41 -07:00
|
|
|
for (const user of users) {
|
|
|
|
const userName = user.given_name;
|
|
|
|
const userId = user.id;
|
|
|
|
returnData.push({
|
|
|
|
name: userName as string,
|
|
|
|
value: userId as string,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2023-04-19 07:00:49 -07:00
|
|
|
// Get all the countries to display them to user so that they can
|
2020-04-01 15:10:41 -07:00
|
|
|
// select them easily
|
|
|
|
async getCountries(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2020-04-02 16:37:40 -07:00
|
|
|
const { countries } = await keapApiRequest.call(this, 'GET', '/locales/countries');
|
2023-02-27 19:39:43 -08:00
|
|
|
for (const key of Object.keys(countries as IDataObject)) {
|
2020-04-01 15:10:41 -07:00
|
|
|
const countryName = countries[key];
|
|
|
|
const countryId = key;
|
|
|
|
returnData.push({
|
|
|
|
name: countryName as string,
|
2022-12-02 12:54:28 -08:00
|
|
|
value: countryId,
|
2020-04-01 15:10:41 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2023-04-19 07:00:49 -07:00
|
|
|
// Get all the provinces to display them to user so that they can
|
2020-04-01 15:10:41 -07:00
|
|
|
// select them easily
|
|
|
|
async getProvinces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const countryCode = this.getCurrentNodeParameter('countryCode') as string;
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-08-17 08:50:24 -07:00
|
|
|
const { provinces } = await keapApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/locales/countries/${countryCode}/provinces`,
|
|
|
|
);
|
2023-02-27 19:39:43 -08:00
|
|
|
for (const key of Object.keys(provinces as IDataObject)) {
|
2020-04-01 15:10:41 -07:00
|
|
|
const provinceName = provinces[key];
|
|
|
|
const provinceId = key;
|
|
|
|
returnData.push({
|
|
|
|
name: provinceName as string,
|
2022-12-02 12:54:28 -08:00
|
|
|
value: provinceId,
|
2020-04-01 15:10:41 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2023-04-19 07:00:49 -07:00
|
|
|
// Get all the contact types to display them to user so that they can
|
2020-04-01 15:10:41 -07:00
|
|
|
// select them easily
|
|
|
|
async getContactTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2020-04-02 16:37:40 -07:00
|
|
|
const types = await keapApiRequest.call(this, 'GET', '/setting/contact/optionTypes');
|
2020-04-01 15:10:41 -07:00
|
|
|
for (const type of types.value.split(',')) {
|
|
|
|
const typeName = type;
|
|
|
|
const typeId = type;
|
|
|
|
returnData.push({
|
|
|
|
name: typeName,
|
|
|
|
value: typeId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2023-04-19 07:00:49 -07:00
|
|
|
// Get all the timezones to display them to user so that they can
|
2020-04-01 15:10:41 -07:00
|
|
|
// select them easily
|
|
|
|
async getTimezones(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
for (const timezone of moment.tz.names()) {
|
|
|
|
const timezoneName = timezone;
|
|
|
|
const timezoneId = timezone;
|
|
|
|
returnData.push({
|
|
|
|
name: timezoneName,
|
|
|
|
value: timezoneId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-04-01 15:10:41 -07:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-04-01 15:10:41 -07:00
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
if (resource === 'company') {
|
2020-04-02 16:37:40 -07:00
|
|
|
//https://developer.keap.com/docs/rest/#!/Company/createCompanyUsingPOST
|
2020-04-01 15:10:41 -07:00
|
|
|
if (operation === 'create') {
|
2022-08-17 08:50:24 -07:00
|
|
|
const addresses = (this.getNodeParameter('addressesUi', i) as IDataObject)
|
|
|
|
.addressesValues as IDataObject[];
|
|
|
|
const faxes = (this.getNodeParameter('faxesUi', i) as IDataObject)
|
|
|
|
.faxesValues as IDataObject[];
|
|
|
|
const phones = (this.getNodeParameter('phonesUi', i) as IDataObject)
|
|
|
|
.phonesValues as IDataObject[];
|
2020-04-01 15:10:41 -07:00
|
|
|
const companyName = this.getNodeParameter('companyName', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: ICompany = {
|
|
|
|
company_name: companyName,
|
|
|
|
};
|
|
|
|
keysToSnakeCase(additionalFields);
|
|
|
|
Object.assign(body, additionalFields);
|
|
|
|
if (addresses) {
|
2021-04-17 07:52:56 -07:00
|
|
|
body.address = keysToSnakeCase(addresses)[0];
|
|
|
|
}
|
|
|
|
if (faxes) {
|
2020-04-01 15:10:41 -07:00
|
|
|
body.fax_number = faxes[0];
|
|
|
|
}
|
|
|
|
if (phones) {
|
|
|
|
body.phone_number = phones[0];
|
|
|
|
}
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'POST', '/companies', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Company/listCompaniesUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
keysToSnakeCase(options);
|
|
|
|
Object.assign(qs, options);
|
|
|
|
if (qs.fields) {
|
|
|
|
qs.optional_properties = qs.fields;
|
|
|
|
delete qs.fields;
|
|
|
|
}
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'companies',
|
|
|
|
'GET',
|
|
|
|
'/companies',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', '/companies', {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.companies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'contact') {
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Contact/createOrUpdateContactUsingPUT
|
2020-04-02 16:37:40 -07:00
|
|
|
if (operation === 'upsert') {
|
2020-04-01 15:10:41 -07:00
|
|
|
const duplicateOption = this.getNodeParameter('duplicateOption', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const addresses = (this.getNodeParameter('addressesUi', i) as IDataObject)
|
|
|
|
.addressesValues as IDataObject[];
|
|
|
|
const emails = (this.getNodeParameter('emailsUi', i) as IDataObject)
|
|
|
|
.emailsValues as IDataObject[];
|
|
|
|
const faxes = (this.getNodeParameter('faxesUi', i) as IDataObject)
|
|
|
|
.faxesValues as IDataObject[];
|
|
|
|
const socialAccounts = (this.getNodeParameter('socialAccountsUi', i) as IDataObject)
|
|
|
|
.socialAccountsValues as IDataObject[];
|
|
|
|
const phones = (this.getNodeParameter('phonesUi', i) as IDataObject)
|
|
|
|
.phonesValues as IDataObject[];
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: IContact = {
|
|
|
|
duplicate_option: pascalCase(duplicateOption),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (additionalFields.anniversary) {
|
|
|
|
body.anniversary = additionalFields.anniversary as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.contactType) {
|
|
|
|
body.contact_type = additionalFields.contactType as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.familyName) {
|
|
|
|
body.family_name = additionalFields.familyName as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.givenName) {
|
|
|
|
body.given_name = additionalFields.givenName as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.jobTitle) {
|
|
|
|
body.job_title = additionalFields.jobTitle as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.leadSourceId) {
|
|
|
|
body.lead_source_id = additionalFields.leadSourceId as number;
|
|
|
|
}
|
|
|
|
if (additionalFields.middleName) {
|
|
|
|
body.middle_name = additionalFields.middleName as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.middleName) {
|
|
|
|
body.middle_name = additionalFields.middleName as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.OptInReason) {
|
|
|
|
body.opt_in_reason = additionalFields.OptInReason as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.ownerId) {
|
|
|
|
body.owner_id = additionalFields.ownerId as number;
|
|
|
|
}
|
|
|
|
if (additionalFields.preferredLocale) {
|
|
|
|
body.preferred_locale = additionalFields.preferredLocale as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.preferredName) {
|
|
|
|
body.preferred_name = additionalFields.preferredName as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.sourceType) {
|
|
|
|
body.source_type = additionalFields.sourceType as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.spouseName) {
|
|
|
|
body.spouse_name = additionalFields.spouseName as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.timezone) {
|
|
|
|
body.time_zone = additionalFields.timezone as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.website) {
|
|
|
|
body.website = additionalFields.website as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.ipAddress) {
|
|
|
|
body.origin = { ip_address: additionalFields.ipAddress as string };
|
|
|
|
}
|
|
|
|
if (additionalFields.companyId) {
|
|
|
|
body.company = { id: additionalFields.companyId as number };
|
|
|
|
}
|
2021-04-17 07:52:56 -07:00
|
|
|
if (additionalFields.optInReason) {
|
|
|
|
body.opt_in_reason = additionalFields.optInReason as string;
|
|
|
|
}
|
2020-04-01 15:10:41 -07:00
|
|
|
if (addresses) {
|
|
|
|
body.addresses = keysToSnakeCase(addresses) as IAddress[];
|
2021-04-17 07:52:56 -07:00
|
|
|
}
|
|
|
|
if (emails) {
|
|
|
|
body.email_addresses = emails as IEmailContact[];
|
|
|
|
}
|
|
|
|
if (faxes) {
|
2020-04-01 15:10:41 -07:00
|
|
|
body.fax_numbers = faxes as IFax[];
|
|
|
|
}
|
|
|
|
if (socialAccounts) {
|
|
|
|
body.social_accounts = socialAccounts as ISocialAccount[];
|
|
|
|
}
|
|
|
|
if (phones) {
|
|
|
|
body.phone_numbers = phones as IPhone[];
|
|
|
|
}
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'PUT', '/contacts', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Contact/deleteContactUsingDELETE
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'DELETE', `/contacts/${contactId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Contact/getContactUsingGET
|
|
|
|
if (operation === 'get') {
|
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
if (options.fields) {
|
|
|
|
qs.optional_properties = options.fields as string;
|
|
|
|
}
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', `/contacts/${contactId}`, {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Contact/listContactsUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
if (options.email) {
|
|
|
|
qs.email = options.email as boolean;
|
|
|
|
}
|
|
|
|
if (options.givenName) {
|
|
|
|
qs.given_name = options.givenName as string;
|
|
|
|
}
|
|
|
|
if (options.familyName) {
|
|
|
|
qs.family_name = options.familyName as boolean;
|
|
|
|
}
|
|
|
|
if (options.order) {
|
|
|
|
qs.order = options.order as string;
|
|
|
|
}
|
|
|
|
if (options.orderDirection) {
|
|
|
|
qs.order_direction = options.orderDirection as string;
|
|
|
|
}
|
|
|
|
if (options.since) {
|
|
|
|
qs.since = options.since as string;
|
|
|
|
}
|
|
|
|
if (options.until) {
|
|
|
|
qs.until = options.until as string;
|
|
|
|
}
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'contacts',
|
|
|
|
'GET',
|
|
|
|
'/contacts',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', '/contacts', {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.contacts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'contactNote') {
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Note/createNoteUsingPOST
|
|
|
|
if (operation === 'create') {
|
|
|
|
const userId = this.getNodeParameter('userId', i) as number;
|
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: INote = {
|
|
|
|
user_id: userId,
|
|
|
|
contact_id: contactId,
|
|
|
|
};
|
|
|
|
keysToSnakeCase(additionalFields);
|
|
|
|
if (additionalFields.type) {
|
|
|
|
additionalFields.type = pascalCase(additionalFields.type as string);
|
|
|
|
}
|
|
|
|
Object.assign(body, additionalFields);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'POST', '/notes', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Note/deleteNoteUsingDELETE
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const noteId = this.getNodeParameter('noteId', i) as string;
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'DELETE', `/notes/${noteId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Note/getNoteUsingGET
|
|
|
|
if (operation === 'get') {
|
|
|
|
const noteId = this.getNodeParameter('noteId', i) as string;
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', `/notes/${noteId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Note/listNotesUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
keysToSnakeCase(filters);
|
|
|
|
Object.assign(qs, filters);
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'notes',
|
|
|
|
'GET',
|
|
|
|
'/notes',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', '/notes', {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.notes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Note/updatePropertiesOnNoteUsingPATCH
|
|
|
|
if (operation === 'update') {
|
|
|
|
const noteId = this.getNodeParameter('noteId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: INote = {};
|
|
|
|
keysToSnakeCase(additionalFields);
|
|
|
|
if (additionalFields.type) {
|
|
|
|
additionalFields.type = pascalCase(additionalFields.type as string);
|
|
|
|
}
|
|
|
|
Object.assign(body, additionalFields);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'PATCH', `/notes/${noteId}`, body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'contactTag') {
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Contact/applyTagsToContactIdUsingPOST
|
|
|
|
if (operation === 'create') {
|
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
|
|
|
const tagIds = this.getNodeParameter('tagIds', i) as number[];
|
|
|
|
const body: IDataObject = {
|
|
|
|
tagIds,
|
|
|
|
};
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/contacts/${contactId}/tags`,
|
|
|
|
body,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Contact/removeTagsFromContactUsingDELETE_1
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
|
|
|
const tagIds = this.getNodeParameter('tagIds', i) as string;
|
|
|
|
qs.ids = tagIds;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequest.call(
|
|
|
|
this,
|
|
|
|
'DELETE',
|
|
|
|
`/contacts/${contactId}/tags`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Contact/listAppliedTagsUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'tags',
|
|
|
|
'GET',
|
|
|
|
`/contacts/${contactId}/tags`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/contacts/${contactId}/tags`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.tags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'ecommerceOrder') {
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/E-Commerce/createOrderUsingPOST
|
|
|
|
if (operation === 'create') {
|
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
|
|
|
const orderDate = this.getNodeParameter('orderDate', i) as string;
|
|
|
|
const orderTitle = this.getNodeParameter('orderTitle', i) as string;
|
|
|
|
const orderType = this.getNodeParameter('orderType', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const orderItems = (this.getNodeParameter('orderItemsUi', i) as IDataObject)
|
|
|
|
.orderItemsValues as IDataObject[];
|
|
|
|
const shippingAddress = (this.getNodeParameter('addressUi', i) as IDataObject)
|
|
|
|
.addressValues as IDataObject;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: IEcommerceOrder = {
|
|
|
|
contact_id: contactId,
|
|
|
|
order_date: orderDate,
|
|
|
|
order_title: orderTitle,
|
|
|
|
order_type: pascalCase(orderType),
|
|
|
|
};
|
|
|
|
if (additionalFields.promoCodes) {
|
2022-12-02 12:54:28 -08:00
|
|
|
additionalFields.promoCodes = (additionalFields.promoCodes as string).split(',');
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
keysToSnakeCase(additionalFields);
|
|
|
|
Object.assign(body, additionalFields);
|
|
|
|
body.order_items = keysToSnakeCase(orderItems) as IItem[];
|
|
|
|
if (shippingAddress) {
|
|
|
|
body.shipping_address = keysToSnakeCase(shippingAddress)[0] as IShippingAddress;
|
|
|
|
}
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'POST', '/orders', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/E-Commerce/deleteOrderUsingDELETE
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const orderId = parseInt(this.getNodeParameter('orderId', i) as string, 10);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'DELETE', `/orders/${orderId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/E-Commerce/getOrderUsingGET
|
|
|
|
if (operation === 'get') {
|
|
|
|
const orderId = parseInt(this.getNodeParameter('orderId', i) as string, 10);
|
2024-02-14 07:29:09 -08:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', `/orders/${orderId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/E-Commerce/listOrdersUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
keysToSnakeCase(options);
|
|
|
|
Object.assign(qs, options);
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'orders',
|
|
|
|
'GET',
|
|
|
|
'/orders',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', '/orders', {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.orders;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'ecommerceProduct') {
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Product/createProductUsingPOST
|
|
|
|
if (operation === 'create') {
|
|
|
|
const productName = this.getNodeParameter('productName', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: IEcommerceProduct = {
|
|
|
|
product_name: productName,
|
|
|
|
};
|
|
|
|
keysToSnakeCase(additionalFields);
|
|
|
|
Object.assign(body, additionalFields);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'POST', '/products', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Product/deleteProductUsingDELETE
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const productId = this.getNodeParameter('productId', i) as string;
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'DELETE', `/products/${productId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Product/retrieveProductUsingGET
|
|
|
|
if (operation === 'get') {
|
|
|
|
const productId = this.getNodeParameter('productId', i) as string;
|
2024-02-14 07:29:09 -08:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', `/products/${productId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Product/listProductsUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
keysToSnakeCase(filters);
|
|
|
|
Object.assign(qs, filters);
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'products',
|
|
|
|
'GET',
|
|
|
|
'/products',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', '/products', {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.products;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'email') {
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Email/createEmailUsingPOST
|
|
|
|
if (operation === 'createRecord') {
|
|
|
|
const sentFromAddress = this.getNodeParameter('sentFromAddress', i) as string;
|
|
|
|
const sendToAddress = this.getNodeParameter('sentToAddress', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
sent_to_address: sendToAddress,
|
|
|
|
sent_from_address: sentFromAddress,
|
|
|
|
};
|
|
|
|
Object.assign(body, additionalFields);
|
2022-12-02 12:54:28 -08:00
|
|
|
keysToSnakeCase(body);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'POST', '/emails', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Email/deleteEmailUsingDELETE
|
|
|
|
if (operation === 'deleteRecord') {
|
|
|
|
const emailRecordId = parseInt(this.getNodeParameter('emailRecordId', i) as string, 10);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'DELETE', `/emails/${emailRecordId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Email/listEmailsUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
keysToSnakeCase(filters);
|
|
|
|
Object.assign(qs, filters);
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'emails',
|
|
|
|
'GET',
|
|
|
|
'/emails',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', '/emails', {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.emails;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/Email/deleteEmailUsingDELETE
|
|
|
|
if (operation === 'send') {
|
|
|
|
const userId = this.getNodeParameter('userId', i) as number;
|
2022-12-02 12:54:28 -08:00
|
|
|
const contactIds = (this.getNodeParameter('contactIds', i) as string)
|
|
|
|
.split(',')
|
|
|
|
.map((e) => parseInt(e, 10));
|
2020-04-01 15:10:41 -07:00
|
|
|
const subject = this.getNodeParameter('subject', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
const body: IEmail = {
|
|
|
|
user_id: userId,
|
|
|
|
contacts: contactIds,
|
|
|
|
subject,
|
|
|
|
};
|
|
|
|
keysToSnakeCase(additionalFields);
|
|
|
|
Object.assign(body, additionalFields);
|
|
|
|
|
|
|
|
const attachmentsUi = this.getNodeParameter('attachmentsUi', i) as IDataObject;
|
|
|
|
let attachments: IAttachment[] = [];
|
|
|
|
if (attachmentsUi) {
|
|
|
|
if (attachmentsUi.attachmentsValues) {
|
|
|
|
keysToSnakeCase(attachmentsUi.attachmentsValues as IDataObject);
|
|
|
|
attachments = attachmentsUi.attachmentsValues as IAttachment[];
|
|
|
|
}
|
2023-03-06 08:33:32 -08:00
|
|
|
const attachmentsBinary = attachmentsUi.attachmentsBinary as Array<{
|
|
|
|
property: string;
|
|
|
|
}>;
|
|
|
|
if (attachmentsBinary?.length) {
|
|
|
|
for (const { property } of attachmentsBinary) {
|
|
|
|
const binaryData = this.helpers.assertBinaryData(i, property);
|
2020-04-01 15:10:41 -07:00
|
|
|
attachments.push({
|
2023-03-06 08:33:32 -08:00
|
|
|
file_data: binaryData.data,
|
|
|
|
file_name: binaryData.fileName,
|
2020-04-01 15:10:41 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
body.attachments = attachments;
|
|
|
|
}
|
|
|
|
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'POST', '/emails/queue', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'file') {
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/File/deleteFileUsingDELETE
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const fileId = parseInt(this.getNodeParameter('fileId', i) as string, 10);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'DELETE', `/files/${fileId}`);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/File/listFilesUsingGET
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2020-04-01 15:10:41 -07:00
|
|
|
keysToSnakeCase(filters);
|
|
|
|
Object.assign(qs, filters);
|
|
|
|
if (qs.permission) {
|
|
|
|
qs.permission = (qs.permission as string).toUpperCase();
|
|
|
|
}
|
|
|
|
if (qs.type) {
|
2020-04-14 12:07:53 -07:00
|
|
|
qs.type = capitalCase(qs.type as string);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
if (qs.viewable) {
|
|
|
|
qs.viewable = (qs.viewable as string).toUpperCase();
|
|
|
|
}
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await keapApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'files',
|
|
|
|
'GET',
|
|
|
|
'/files',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'GET', '/files', {}, qs);
|
2020-04-01 15:10:41 -07:00
|
|
|
responseData = responseData.files;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//https://developer.infusionsoft.com/docs/rest/#!/File/createFileUsingPOST
|
|
|
|
if (operation === 'upload') {
|
|
|
|
const fileAssociation = this.getNodeParameter('fileAssociation', i) as string;
|
|
|
|
const isPublic = this.getNodeParameter('isPublic', i) as boolean;
|
|
|
|
const body: IFile = {
|
|
|
|
is_public: isPublic,
|
|
|
|
file_association: fileAssociation.toUpperCase(),
|
|
|
|
};
|
|
|
|
if (fileAssociation === 'contact') {
|
|
|
|
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
|
|
|
|
body.contact_id = contactId;
|
|
|
|
}
|
2023-03-06 08:33:32 -08:00
|
|
|
if (this.getNodeParameter('binaryData', i)) {
|
2023-01-06 06:09:32 -08:00
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
2023-03-06 08:33:32 -08:00
|
|
|
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
|
|
|
body.file_data = binaryData.data;
|
|
|
|
body.file_name = binaryData.fileName;
|
2020-04-01 15:10:41 -07:00
|
|
|
} else {
|
|
|
|
const fileName = this.getNodeParameter('fileName', i) as string;
|
|
|
|
const fileData = this.getNodeParameter('fileData', i) as string;
|
|
|
|
body.file_name = fileName;
|
|
|
|
body.file_data = fileData;
|
|
|
|
}
|
2020-04-02 16:37:40 -07:00
|
|
|
responseData = await keapApiRequest.call(this, 'POST', '/files', body);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
2023-09-05 03:59:02 -07:00
|
|
|
return [returnData];
|
2020-04-01 15:10:41 -07:00
|
|
|
}
|
|
|
|
}
|