Skip to content

Commit

Permalink
⚡ Add search operation to Zendesk-Node (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 authored Aug 31, 2020
1 parent 785858e commit 0c2db74
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
81 changes: 80 additions & 1 deletion packages/nodes-base/nodes/Zendesk/UserDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const userOperations = [
value: 'getAll',
description: 'Get all users',
},
{
name: 'Search',
value: 'search',
description: 'Search users',
},
{
name: 'Update',
value: 'update',
Expand Down Expand Up @@ -667,7 +672,81 @@ export const userFields = [
},
],
},

/* -------------------------------------------------------------------------- */
/* user:search */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'search',
],
},
},
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: [
'user',
],
operation: [
'search',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'search',
],
},
},
options: [
{
displayName: 'Query',
name: 'query',
type: 'string',
default: '',
},
{
displayName: 'External ID',
name: 'external_id',
type: 'string',
default: '',
},
],
},
/* -------------------------------------------------------------------------- */
/* user:delete */
/* -------------------------------------------------------------------------- */
Expand Down
16 changes: 16 additions & 0 deletions packages/nodes-base/nodes/Zendesk/Zendesk.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,22 @@ export class Zendesk implements INodeType {
responseData = responseData.users;
}
}
//https://developer.zendesk.com/rest_api/docs/support/users#search-users
if (operation === 'search') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const options = this.getNodeParameter('filters', i) as IDataObject;

Object.assign(qs, options);

if (returnAll) {
responseData = await zendeskApiRequestAllItems.call(this, 'users', 'GET', `/users/search`, {}, qs);
} else {
const limit = this.getNodeParameter('limit', i) as number;
qs.per_page = limit;
responseData = await zendeskApiRequest.call(this, 'GET', `/users/search`, {}, qs);
responseData = responseData.users;
}
}
//https://developer.zendesk.com/rest_api/docs/support/users#delete-user
if (operation === 'delete') {
const userId = this.getNodeParameter('id', i) as string;
Expand Down

0 comments on commit 0c2db74

Please sign in to comment.