mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
⚡ Add search operation to resource person
This commit is contained in:
parent
c152c0f959
commit
5adec0a299
|
@ -48,6 +48,9 @@ export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||||
query.api_token = credentials.apiToken;
|
query.api_token = credentials.apiToken;
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
method,
|
method,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: `https://api.pipedrive.com/v1${endpoint}`,
|
uri: `https://api.pipedrive.com/v1${endpoint}`,
|
||||||
|
@ -93,7 +96,7 @@ export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||||
|
|
||||||
if (error.response && error.response.body && error.response.body.error) {
|
if (error.response && error.response.body && error.response.body.error) {
|
||||||
// Try to return the error prettier
|
// Try to return the error prettier
|
||||||
let errorMessage = `Pipedrive error response [${error.statusCode}]: ${error.response.body.error}`;
|
let errorMessage = `Pipedrive error response [${error.statusCode}]: ${error.response.body.error.message}`;
|
||||||
if (error.response.body.error_info) {
|
if (error.response.body.error_info) {
|
||||||
errorMessage += ` - ${error.response.body.error_info}`;
|
errorMessage += ` - ${error.response.body.error_info}`;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +127,7 @@ export async function pipedriveApiRequestAllItems(this: IHookFunctions | IExecut
|
||||||
if (query === undefined) {
|
if (query === undefined) {
|
||||||
query = {};
|
query = {};
|
||||||
}
|
}
|
||||||
query.limit = 500;
|
query.limit = 100;
|
||||||
query.start = 0;
|
query.start = 0;
|
||||||
|
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
@ -133,7 +136,12 @@ export async function pipedriveApiRequestAllItems(this: IHookFunctions | IExecut
|
||||||
|
|
||||||
do {
|
do {
|
||||||
responseData = await pipedriveApiRequest.call(this, method, endpoint, body, query);
|
responseData = await pipedriveApiRequest.call(this, method, endpoint, body, query);
|
||||||
returnData.push.apply(returnData, responseData.data);
|
// the search path returns data diferently
|
||||||
|
if (responseData.data.items) {
|
||||||
|
returnData.push.apply(returnData, responseData.data.items);
|
||||||
|
} else {
|
||||||
|
returnData.push.apply(returnData, responseData.data);
|
||||||
|
}
|
||||||
|
|
||||||
query.start = responseData.additionalData.pagination.next_start;
|
query.start = responseData.additionalData.pagination.next_start;
|
||||||
} while (
|
} while (
|
||||||
|
|
|
@ -25,7 +25,6 @@ interface CustomProperty {
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the additional fields to the body
|
* Add the additional fields to the body
|
||||||
*
|
*
|
||||||
|
@ -362,6 +361,11 @@ export class Pipedrive implements INodeType {
|
||||||
value: 'getAll',
|
value: 'getAll',
|
||||||
description: 'Get data of all persons',
|
description: 'Get data of all persons',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Search',
|
||||||
|
value: 'search',
|
||||||
|
description: 'Search all persons',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Update',
|
name: 'Update',
|
||||||
value: 'update',
|
value: 'update',
|
||||||
|
@ -2021,6 +2025,7 @@ export class Pipedrive implements INodeType {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
'search',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -2035,6 +2040,7 @@ export class Pipedrive implements INodeType {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
'search',
|
||||||
],
|
],
|
||||||
returnAll: [
|
returnAll: [
|
||||||
false,
|
false,
|
||||||
|
@ -2088,6 +2094,74 @@ export class Pipedrive implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// person:search
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Term',
|
||||||
|
name: 'term',
|
||||||
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'search',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'person',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'The search term to look for. Minimum 2 characters (or 1 if using exact_match).',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'search',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'person',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Exact Match',
|
||||||
|
name: 'exactMatch',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'When enabled, only full exact matches against the given term are returned. It is not case sensitive.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Fields',
|
||||||
|
name: 'fields',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'A comma-separated string array. The fields to perform the search from. Defaults to all of them.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Include Fields',
|
||||||
|
name: 'includeFields',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Supports including optional fields in the results which are not provided by default.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Organization ID',
|
||||||
|
name: 'organizationId',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Will filter Deals by the provided Organization ID.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2526,6 +2600,39 @@ export class Pipedrive implements INodeType {
|
||||||
|
|
||||||
endpoint = `/persons`;
|
endpoint = `/persons`;
|
||||||
|
|
||||||
|
} else if (operation === 'search') {
|
||||||
|
// ----------------------------------
|
||||||
|
// persons:search
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
requestMethod = 'GET';
|
||||||
|
|
||||||
|
qs.term = this.getNodeParameter('term', i) as string;
|
||||||
|
returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
if (returnAll === false) {
|
||||||
|
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
if (additionalFields.fields) {
|
||||||
|
qs.fields = additionalFields.fields as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.exactMatch) {
|
||||||
|
qs.exact_match = additionalFields.exactMatch as boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.organizationId) {
|
||||||
|
qs.organization_id = parseInt(additionalFields.organizationId as string, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.includeFields) {
|
||||||
|
qs.include_fields = additionalFields.includeFields as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
endpoint = `/persons/search`;
|
||||||
|
|
||||||
} else if (operation === 'update') {
|
} else if (operation === 'update') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// person:update
|
// person:update
|
||||||
|
@ -2562,7 +2669,9 @@ export class Pipedrive implements INodeType {
|
||||||
|
|
||||||
let responseData;
|
let responseData;
|
||||||
if (returnAll === true) {
|
if (returnAll === true) {
|
||||||
|
|
||||||
responseData = await pipedriveApiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
|
responseData = await pipedriveApiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (customProperties !== undefined) {
|
if (customProperties !== undefined) {
|
||||||
|
@ -2597,6 +2706,10 @@ export class Pipedrive implements INodeType {
|
||||||
responseData.data = [];
|
responseData.data = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (operation === 'search' && responseData.data && responseData.data.items) {
|
||||||
|
responseData.data = responseData.data.items;
|
||||||
|
}
|
||||||
|
|
||||||
if (Array.isArray(responseData.data)) {
|
if (Array.isArray(responseData.data)) {
|
||||||
returnData.push.apply(returnData, responseData.data as IDataObject[]);
|
returnData.push.apply(returnData, responseData.data as IDataObject[]);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue