From 223f0130f066c880a1708d4fe9d09984e57597d7 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 24 Apr 2021 17:42:31 +0200 Subject: [PATCH] :zap: Fix company:users response --- .../nodes/Intercom/CompanyDescription.ts | 43 ++++++++++++++++++- .../nodes/Intercom/Intercom.node.ts | 21 ++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Intercom/CompanyDescription.ts b/packages/nodes-base/nodes/Intercom/CompanyDescription.ts index d8734b5122..d547588fce 100644 --- a/packages/nodes-base/nodes/Intercom/CompanyDescription.ts +++ b/packages/nodes-base/nodes/Intercom/CompanyDescription.ts @@ -49,7 +49,6 @@ export const companyFields = [ /* -------------------------------------------------------------------------- */ /* company:users */ /* -------------------------------------------------------------------------- */ - { displayName: 'List By', name: 'listBy', @@ -97,6 +96,48 @@ export const companyFields = [ }, description: 'View by value', }, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'users', + ], + }, + }, + default: false, + description: 'If all results should be returned or only up to a given limit.', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'users', + ], + returnAll: [ + false, + ], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 60, + }, + default: 50, + description: 'How many results to return.', + }, + /* -------------------------------------------------------------------------- */ /* company:getAll */ /* -------------------------------------------------------------------------- */ diff --git a/packages/nodes-base/nodes/Intercom/Intercom.node.ts b/packages/nodes-base/nodes/Intercom/Intercom.node.ts index 44b50406cd..fd13f91e96 100644 --- a/packages/nodes-base/nodes/Intercom/Intercom.node.ts +++ b/packages/nodes-base/nodes/Intercom/Intercom.node.ts @@ -514,15 +514,32 @@ export class Intercom implements INodeType { if (operation === 'users') { const listBy = this.getNodeParameter('listBy', 0) as string; const value = this.getNodeParameter('value', i) as string; + const returnAll = this.getNodeParameter('returnAll', i) as boolean; + if (listBy === 'companyId') { qs.company_id = value; } + try { if (listBy === 'id') { - responseData = await intercomApiRequest.call(this, `/companies/${value}/users`, 'GET', {}, qs); + if (returnAll === true) { + responseData = await intercomApiRequestAllItems.call(this, 'users', `/companies/${value}/users`, 'GET', {}, qs); + } else { + qs.per_page = this.getNodeParameter('limit', i) as number; + responseData = await intercomApiRequest.call(this, `/companies/${value}/users`, 'GET', {}, qs); + responseData = responseData.users; + } + } else { qs.type = 'users'; - responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs); + + if (returnAll === true) { + responseData = await intercomApiRequestAllItems.call(this, 'users', '/companies', 'GET', {}, qs); + } else { + qs.per_page = this.getNodeParameter('limit', i) as number; + responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs); + responseData = responseData.users; + } } } catch (error) { throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`);