Revert commit

This commit is contained in:
Jan Oberhauser 2019-09-11 21:56:45 +02:00
parent 90f2dcb4c9
commit 9b95072be8
3 changed files with 99 additions and 145 deletions

View file

@ -2,29 +2,6 @@
This list shows all the versions which include breaking changes and how to upgrade This list shows all the versions which include breaking changes and how to upgrade
## 0.20.0
### What changed?
The node "ActiveCampaign" had to be changed to use v1 of their API. That API is sadly
quite bad but at least it is feature complete which their v3 sadly is not.
### When is action necessary?
If a "ActiveCampaign" node gets used in any workflow.
### How to upgrade:
After upgrading open all workflows which contain a "Read File From Url" node.
They will have a "?" as icon as they are not known anymore. Create a new
"HTTP Request" node to replace the old one and add the same URL as the previous
node had (in case you do not know it anymore you can select the old node, copy
it and paste it in a text-editor, it will display all the data the node
contained). Then set the "Response Format" to "File". Everything will then
function again like before.
## 0.19.0 ## 0.19.0
### What changed? ### What changed?

View file

@ -183,14 +183,14 @@ export class ActiveCampaign implements INodeType {
options: [ options: [
{ {
displayName: 'First Name', displayName: 'First Name',
name: 'first_name', name: 'firstName',
type: 'string', type: 'string',
default: '', default: '',
description: 'The first name of the contact to create', description: 'The first name of the contact to create',
}, },
{ {
displayName: 'Last Name', displayName: 'Last Name',
name: 'last_name', name: 'lastName',
type: 'string', type: 'string',
default: '', default: '',
description: 'The last name of the contact to create', description: 'The last name of the contact to create',
@ -282,68 +282,50 @@ export class ActiveCampaign implements INodeType {
description: 'ID of the contact to get.', description: 'ID of the contact to get.',
}, },
// TODO: Does not work as expted so remove for now // ----------------------------------
// // ---------------------------------- // contact:getAll
// // contact:getAll // ----------------------------------
// // ---------------------------------- {
// { displayName: 'Return All',
// displayName: 'Full User Data', name: 'returnAll',
// name: 'fullUserData', type: 'boolean',
// type: 'boolean', displayOptions: {
// displayOptions: { show: {
// show: { operation: [
// operation: [ 'getAll',
// 'getAll', ],
// ], resource: [
// resource: [ 'contact',
// 'contact', ],
// ], },
// }, },
// }, default: false,
// default: false, description: 'If all results should be returned or only up to a given limit.',
// description: 'If all data of the user should be returned or an abbreviated version.', },
// }, {
// { displayName: 'Limit',
// displayName: 'Return All', name: 'limit',
// name: 'returnAll', type: 'number',
// type: 'boolean', displayOptions: {
// displayOptions: { show: {
// show: { operation: [
// operation: [ 'getAll',
// 'getAll', ],
// ], resource: [
// resource: [ 'contact',
// 'contact', ],
// ], returnAll: [
// }, false,
// }, ],
// default: false, },
// description: 'If all results should be returned or only results of a given page.', },
// }, typeOptions: {
// { minValue: 1,
// displayName: 'Page', maxValue: 500,
// name: 'page', },
// type: 'number', default: 100,
// displayOptions: { description: 'How many results to return.',
// show: { },
// operation: [
// 'getAll',
// ],
// resource: [
// 'contact',
// ],
// returnAll: [
// false,
// ],
// },
// },
// typeOptions: {
// minValue: 1,
// maxValue: 500,
// },
// default: 1,
// description: 'Maximum 20 results per page get returned. Set which page to return.',
// },
// ---------------------------------- // ----------------------------------
// contact:update // contact:update
@ -393,14 +375,14 @@ export class ActiveCampaign implements INodeType {
}, },
{ {
displayName: 'First Name', displayName: 'First Name',
name: 'first_name', name: 'firstName',
type: 'string', type: 'string',
default: '', default: '',
description: 'First name of the contact', description: 'First name of the contact',
}, },
{ {
displayName: 'Last Name', displayName: 'Last Name',
name: 'last_name', name: 'lastName',
type: 'string', type: 'string',
default: '', default: '',
description: 'Last name of the contact', description: 'Last name of the contact',
@ -465,16 +447,17 @@ export class ActiveCampaign implements INodeType {
let qs: IDataObject; let qs: IDataObject;
let requestMethod: string; let requestMethod: string;
const endpoint = '/admin/api.php'; let endpoint: string;
let returnAll = false; let returnAll = false;
let dataKeys: string[] | undefined; let dataKey: string | undefined;
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
dataKey = undefined;
resource = this.getNodeParameter('resource', 0) as string; resource = this.getNodeParameter('resource', 0) as string;
operation = this.getNodeParameter('operation', 0) as string; operation = this.getNodeParameter('operation', 0) as string;
dataKeys = undefined;
requestMethod = 'GET'; requestMethod = 'GET';
endpoint = '';
body = {} as IDataObject; body = {} as IDataObject;
qs = {} as IDataObject; qs = {} as IDataObject;
@ -488,27 +471,27 @@ export class ActiveCampaign implements INodeType {
const updateIfExists = this.getNodeParameter('updateIfExists', i) as boolean; const updateIfExists = this.getNodeParameter('updateIfExists', i) as boolean;
if (updateIfExists === true) { if (updateIfExists === true) {
qs.api_action = 'contact_sync'; endpoint = '/api/3/contact/sync';
} else { } else {
qs.api_action = 'contact_add'; endpoint = '/api/3/contacts';
} }
dataKeys = ['subscriber_id']; dataKey = 'contact';
body.contact = {
body.email = this.getNodeParameter('email', i) as string; email: this.getNodeParameter('email', i) as string,
} as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
addAdditionalFields(body as IDataObject, additionalFields); addAdditionalFields(body.contact as IDataObject, additionalFields);
} else if (operation === 'delete') { } else if (operation === 'delete') {
// ---------------------------------- // ----------------------------------
// contact:delete // contact:delete
// ---------------------------------- // ----------------------------------
requestMethod = 'GET'; requestMethod = 'DELETE';
qs.api_action = 'contact_delete';
const contactId = this.getNodeParameter('contactId', i) as number; const contactId = this.getNodeParameter('contactId', i) as number;
qs.id = contactId; endpoint = `/api/3/contacts/${contactId}`;
} else if (operation === 'get') { } else if (operation === 'get') {
// ---------------------------------- // ----------------------------------
@ -516,45 +499,39 @@ export class ActiveCampaign implements INodeType {
// ---------------------------------- // ----------------------------------
requestMethod = 'GET'; requestMethod = 'GET';
qs.api_action = 'contact_view';
const contactId = this.getNodeParameter('contactId', i) as number; const contactId = this.getNodeParameter('contactId', i) as number;
qs.id = contactId; endpoint = `/api/3/contacts/${contactId}`;
// TODO: Does not work as expted so remove for now } else if (operation === 'getAll') {
// } else if (operation === 'getAll') { // ----------------------------------
// // ---------------------------------- // persons:getAll
// // contact:getAll // ----------------------------------
// // ----------------------------------
// requestMethod = 'GET'; requestMethod = 'GET';
// qs.api_action = 'contact_list';
// qs.ids = 'ALL';
// returnAll = this.getNodeParameter('returnAll', i) as boolean; returnAll = this.getNodeParameter('returnAll', i) as boolean;
// if (returnAll === false) { if (returnAll === false) {
// qs.page = this.getNodeParameter('page', i) as number; qs.limit = this.getNodeParameter('limit', i) as number;
// } }
// const fullUserData = this.getNodeParameter('fullUserData', i) as boolean; dataKey = 'contacts';
// qs.full = fullUserData === true ? 1 : 0; endpoint = `/api/3/contacts`;
} else if (operation === 'update') { } else if (operation === 'update') {
// ---------------------------------- // ----------------------------------
// contact:update // contact:update
// ---------------------------------- // ----------------------------------
requestMethod = 'POST'; requestMethod = 'PUT';
const contactId = this.getNodeParameter('contactId', i) as number; const contactId = this.getNodeParameter('contactId', i) as number;
qs.api_action = 'contact_edit'; endpoint = `/api/3/contacts/${contactId}`;
qs.overwrite = 0;
dataKeys = ['subscriber_id']; dataKey = 'contact';
body.contact = {} as IDataObject;
body.id = contactId;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
addAdditionalFields(body as IDataObject, updateFields); addAdditionalFields(body.contact as IDataObject, updateFields);
} }
} else { } else {
@ -563,9 +540,9 @@ export class ActiveCampaign implements INodeType {
let responseData; let responseData;
if (returnAll === true) { if (returnAll === true) {
responseData = await activeCampaignApiRequestAllItems.call(this, requestMethod, endpoint, body, qs, dataKeys); responseData = await activeCampaignApiRequestAllItems.call(this, requestMethod, endpoint, body, qs, dataKey);
} else { } else {
responseData = await activeCampaignApiRequest.call(this, requestMethod, endpoint, body, qs, dataKeys); responseData = await activeCampaignApiRequest.call(this, requestMethod, endpoint, body, qs, dataKey);
} }
if (Array.isArray(responseData)) { if (Array.isArray(responseData)) {

View file

@ -19,7 +19,7 @@ import { OptionsWithUri } from 'request';
* @param {object} body * @param {object} body
* @returns {Promise<any>} * @returns {Promise<any>}
*/ */
export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, dataKeys?: string[]): Promise<any> { // tslint:disable-line:no-any export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, dataKey?: string): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('activeCampaignApi'); const credentials = this.getCredentials('activeCampaignApi');
if (credentials === undefined) { if (credentials === undefined) {
throw new Error('No credentials got returned!'); throw new Error('No credentials got returned!');
@ -29,10 +29,10 @@ export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFu
query = {}; query = {};
} }
query.api_key = credentials.apiKey;
query.api_output = 'json';
const options: OptionsWithUri = { const options: OptionsWithUri = {
headers: {
'Api-Token': credentials.apiKey,
},
method, method,
qs: query, qs: query,
uri: `${credentials.apiUrl}${endpoint}`, uri: `${credentials.apiUrl}${endpoint}`,
@ -40,27 +40,22 @@ export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFu
}; };
if (Object.keys(body).length !== 0) { if (Object.keys(body).length !== 0) {
options.form = body; options.body = body;
} }
const returnData: IDataObject = {};
try { try {
const responseData = await this.helpers.request(options); const responseData = await this.helpers.request(options);
if (responseData.result_code === 0) { if (responseData.success === false) {
throw new Error(`ActiveCampaign error response: ${responseData.result_message}`); throw new Error(`ActiveCampaign error response: ${responseData.error} (${responseData.error_info})`);
} }
if (dataKeys === undefined) { if (dataKey === undefined) {
return responseData; return responseData;
} else {
return responseData[dataKey] as IDataObject;
} }
for (const dataKey of dataKeys) {
returnData[dataKey] = responseData[dataKey];
}
return returnData;
} catch (error) { } catch (error) {
if (error.statusCode === 403) { if (error.statusCode === 403) {
// Return a clear error // Return a clear error
@ -86,7 +81,7 @@ export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFu
* @param {IDataObject} [query] * @param {IDataObject} [query]
* @returns {Promise<any>} * @returns {Promise<any>}
*/ */
export async function activeCampaignApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, dataKeys?: string[]): Promise<any> { // tslint:disable-line:no-any export async function activeCampaignApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, dataKey?: string): Promise<any> { // tslint:disable-line:no-any
if (query === undefined) { if (query === undefined) {
query = {}; query = {};
@ -100,10 +95,15 @@ export async function activeCampaignApiRequestAllItems(this: IHookFunctions | IE
let itemsReceived = 0; let itemsReceived = 0;
do { do {
responseData = await activeCampaignApiRequest.call(this, method, endpoint, body, query, dataKeys); responseData = await activeCampaignApiRequest.call(this, method, endpoint, body, query);
returnData.push.apply(returnData, responseData); if (dataKey === undefined) {
itemsReceived += returnData.length; returnData.push.apply(returnData, responseData);
itemsReceived += returnData.length;
} else {
returnData.push.apply(returnData, responseData[dataKey]);
itemsReceived += responseData[dataKey].length;
}
query.offset = itemsReceived; query.offset = itemsReceived;
} while ( } while (