finish ecom order endpoints

This commit is contained in:
quansenB 2019-11-02 23:11:55 +01:00
parent a69426d6ba
commit 6bd391a35e
2 changed files with 113 additions and 12 deletions

View file

@ -7,12 +7,12 @@ import {
INodeTypeDescription, INodeTypeDescription,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodePropertyOptions,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
activeCampaignApiRequest, activeCampaignApiRequest,
activeCampaignApiRequestAllItems, activeCampaignApiRequestAllItems,
IProduct,
} from './GenericFunctions'; } from './GenericFunctions';
import { returnAllCurrencyOptions } from './currencies' import { returnAllCurrencyOptions } from './currencies'
@ -623,7 +623,7 @@ export class ActiveCampaign implements INodeType {
}, },
{ {
displayName: 'Deal pipeline ID', displayName: 'Deal pipeline ID',
name: 'owner', name: 'group',
type: 'string', type: 'string',
default: '', default: '',
displayOptions: { displayOptions: {
@ -791,7 +791,7 @@ export class ActiveCampaign implements INodeType {
}, },
{ {
displayName: 'Deal pipeline ID', displayName: 'Deal pipeline ID',
name: 'owner', name: 'group',
type: 'string', type: 'string',
default: '', default: '',
description: 'The pipeline ID of the deal', description: 'The pipeline ID of the deal',
@ -1379,7 +1379,7 @@ export class ActiveCampaign implements INodeType {
{ {
displayName: 'Add Field', displayName: 'Add Field',
name: 'additionalFields', name: 'updateFields',
type: 'collection', type: 'collection',
placeholder: 'Add Field', placeholder: 'Add Field',
displayOptions: { displayOptions: {
@ -1805,9 +1805,10 @@ export class ActiveCampaign implements INodeType {
title: this.getNodeParameter('title', i) as string, title: this.getNodeParameter('title', i) as string,
contact: this.getNodeParameter('contact', i) as string, contact: this.getNodeParameter('contact', i) as string,
value: this.getNodeParameter('value', i) as number, value: this.getNodeParameter('value', i) as number,
currency: this.getNodeParameter('currency', i) as string
} as IDataObject; } as IDataObject;
const group = this.getNodeParameter('owner', i) as string const group = this.getNodeParameter('group', i) as string
if (group !== '') { if (group !== '') {
addAdditionalFields(body.deal as IDataObject, { group }) addAdditionalFields(body.deal as IDataObject, { group })
} }
@ -1822,9 +1823,6 @@ export class ActiveCampaign implements INodeType {
addAdditionalFields(body.deal as IDataObject, { stage }) addAdditionalFields(body.deal as IDataObject, { stage })
} }
const currency = this.getNodeParameter('currency', i) as string
addAdditionalFields(body.deal as IDataObject, { currency })
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
addAdditionalFields(body.deal as IDataObject, additionalFields); addAdditionalFields(body.deal as IDataObject, additionalFields);
@ -1906,6 +1904,103 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/deals/${dealId}/notes/${dealNoteId}`; endpoint = `/api/3/deals/${dealId}/notes/${dealNoteId}`;
} else {
throw new Error(`The operation "${operation}" is not known`);
}
} else if (resource === 'ecommerceOrder') {
if (operation === 'create') {
// ----------------------------------
// ecommerceOrder:create
// ----------------------------------
requestMethod = 'POST';
endpoint = '/api/3/ecomOrders';
dataKey = 'ecommerceOrder';
body.ecomOrder = {
source: this.getNodeParameter('source', i) as string,
email: this.getNodeParameter('email', i) as string,
totalPrice: this.getNodeParameter('totalPrice', i) as number,
currency: this.getNodeParameter('currency', i).toString().toUpperCase() as string,
externalCreatedDate: this.getNodeParameter('externalCreatedDate', i) as string,
connectionid: this.getNodeParameter('connectionid', i) as number,
customerid: this.getNodeParameter('customerid', i) as number,
} as IDataObject;
const externalid = this.getNodeParameter('externalid', i) as string;
if (externalid !== '') {
addAdditionalFields(body.ecomOrder as IDataObject, { externalid });
}
const externalcheckoutid = this.getNodeParameter('externalcheckoutid', i) as string;
if (externalcheckoutid !== '') {
addAdditionalFields(body.ecomOrder as IDataObject, { externalcheckoutid });
}
const abandonedDate = this.getNodeParameter('abandonedDate', i) as string;
if (abandonedDate !== '') {
addAdditionalFields(body.ecomOrder as IDataObject, { abandonedDate });
}
const orderProducts = this.getNodeParameter('orderProducts', i) as unknown as IProduct[];
addAdditionalFields(body.ecomOrder as IDataObject, { orderProducts });
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
addAdditionalFields(body.ecomOrder as IDataObject, additionalFields);
} else if (operation === 'update') {
// ----------------------------------
// ecommerceOrder:update
// ----------------------------------
requestMethod = 'PUT';
const orderId = this.getNodeParameter('orderId', i) as number;
endpoint = `/api/3/ecomOrders/${orderId}`;
dataKey = 'ecommerceOrder';
body.ecomOrder = {} as IDataObject;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
addAdditionalFields(body.ecomOrder as IDataObject, updateFields);
} else if (operation === 'delete') {
// ----------------------------------
// ecommerceOrder:delete
// ----------------------------------
requestMethod = 'DELETE';
const orderId = this.getNodeParameter('orderId', i) as number;
endpoint = `/api/3/ecomOrders/${orderId}`;
} else if (operation === 'get') {
// ----------------------------------
// ecommerceOrder:get
// ----------------------------------
requestMethod = 'GET';
const orderId = this.getNodeParameter('orderId', i) as number;
endpoint = `/api/3/ecomOrders/${orderId}`;
} else if (operation === 'getAll') {
// ----------------------------------
// ecommerceOrders:getAll
// ----------------------------------
requestMethod = 'GET';
returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll === false) {
qs.limit = this.getNodeParameter('limit', i) as number;
}
dataKey = 'ecommerceOrders';
endpoint = `/api/3/ecomOrders`;
} else { } else {
throw new Error(`The operation "${operation}" is not known`); throw new Error(`The operation "${operation}" is not known`);
} }

View file

@ -9,6 +9,12 @@ import {
import { OptionsWithUri } from 'request'; import { OptionsWithUri } from 'request';
export interface IProduct {
fields: {
item?: object[];
};
}
/** /**
* Make an API request to ActiveCampaign * Make an API request to ActiveCampaign