diff --git a/components/pipedrive/actions/add-activity/add-activity.mjs b/components/pipedrive/actions/add-activity/add-activity.mjs index 8b35382a7f459..1cfc915786aee 100644 --- a/components/pipedrive/actions/add-activity/add-activity.mjs +++ b/components/pipedrive/actions/add-activity/add-activity.mjs @@ -7,7 +7,7 @@ export default { key: "pipedrive-add-activity", name: "Add Activity", description: "Adds a new activity. Includes `more_activities_scheduled_in_context` property in response's `additional_data` which indicates whether there are more undone activities scheduled with the same deal, person or organization (depending on the supplied data). See the Pipedrive API docs for Activities [here](https://developers.pipedrive.com/docs/api/v1/#!/Activities). For info on [adding an activity in Pipedrive](https://developers.pipedrive.com/docs/api/v1/Activities#addActivity)", - version: "0.1.16", + version: "0.1.17", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/add-deal/add-deal.mjs b/components/pipedrive/actions/add-deal/add-deal.mjs index a54635b229f8d..c31429cb2071c 100644 --- a/components/pipedrive/actions/add-deal/add-deal.mjs +++ b/components/pipedrive/actions/add-deal/add-deal.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-add-deal", name: "Add Deal", description: "Adds a new deal. See the Pipedrive API docs for Deals [here](https://developers.pipedrive.com/docs/api/v1/Deals#addDeal)", - version: "0.1.17", + version: "0.1.18", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/add-lead/add-lead.mjs b/components/pipedrive/actions/add-lead/add-lead.mjs index bd13b3bcfcc14..ed6ae3cc19343 100644 --- a/components/pipedrive/actions/add-lead/add-lead.mjs +++ b/components/pipedrive/actions/add-lead/add-lead.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-add-lead", name: "Add Lead", description: "Create a new lead in Pipedrive. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Leads#addLead)", - version: "0.0.10", + version: "0.0.11", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/add-note/add-note.mjs b/components/pipedrive/actions/add-note/add-note.mjs index 225e6c12fb366..973fe7c05d688 100644 --- a/components/pipedrive/actions/add-note/add-note.mjs +++ b/components/pipedrive/actions/add-note/add-note.mjs @@ -5,7 +5,7 @@ export default { key: "pipedrive-add-note", name: "Add Note", description: "Adds a new note. For info on [adding an note in Pipedrive](https://developers.pipedrive.com/docs/api/v1/Notes#addNote)", - version: "0.0.14", + version: "0.0.15", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/add-organization/add-organization.mjs b/components/pipedrive/actions/add-organization/add-organization.mjs index 3320a92308da8..8bae7fab15ec6 100644 --- a/components/pipedrive/actions/add-organization/add-organization.mjs +++ b/components/pipedrive/actions/add-organization/add-organization.mjs @@ -5,7 +5,7 @@ export default { key: "pipedrive-add-organization", name: "Add Organization", description: "Adds a new organization. See the Pipedrive API docs for Organizations [here](https://developers.pipedrive.com/docs/api/v1/Organizations#addOrganization)", - version: "0.1.16", + version: "0.1.17", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/add-person/add-person.mjs b/components/pipedrive/actions/add-person/add-person.mjs index b924184b5b805..03621655ec7f5 100644 --- a/components/pipedrive/actions/add-person/add-person.mjs +++ b/components/pipedrive/actions/add-person/add-person.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-add-person", name: "Add Person", description: "Adds a new person. See the Pipedrive API docs for People [here](https://developers.pipedrive.com/docs/api/v1/Persons#addPerson)", - version: "0.1.16", + version: "0.1.17", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/get-lead-by-id/get-lead-by-id.mjs b/components/pipedrive/actions/get-lead-by-id/get-lead-by-id.mjs index 03fa674153421..5ab9896681376 100644 --- a/components/pipedrive/actions/get-lead-by-id/get-lead-by-id.mjs +++ b/components/pipedrive/actions/get-lead-by-id/get-lead-by-id.mjs @@ -4,7 +4,7 @@ export default { key: "pipedrive-get-lead-by-id", name: "Get Lead by ID", description: "Get a lead by its ID. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Leads#getLead)", - version: "0.0.4", + version: "0.0.5", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/get-person-details/get-person-details.mjs b/components/pipedrive/actions/get-person-details/get-person-details.mjs index d04b988e6346a..adca402d58860 100644 --- a/components/pipedrive/actions/get-person-details/get-person-details.mjs +++ b/components/pipedrive/actions/get-person-details/get-person-details.mjs @@ -5,7 +5,7 @@ export default { key: "pipedrive-get-person-details", name: "Get person details", description: "Get details of a person by their ID. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Persons#getPerson)", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/merge-deals/merge-deals.mjs b/components/pipedrive/actions/merge-deals/merge-deals.mjs index 6bf3e4297301b..c6de4083a182e 100644 --- a/components/pipedrive/actions/merge-deals/merge-deals.mjs +++ b/components/pipedrive/actions/merge-deals/merge-deals.mjs @@ -4,7 +4,7 @@ export default { key: "pipedrive-merge-deals", name: "Merge Deals", description: "Merge two deals in Pipedrive. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Deals#mergeDeals)", - version: "0.0.4", + version: "0.0.5", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/merge-persons/merge-persons.mjs b/components/pipedrive/actions/merge-persons/merge-persons.mjs index 2366187bed9f2..3025b5e270e58 100644 --- a/components/pipedrive/actions/merge-persons/merge-persons.mjs +++ b/components/pipedrive/actions/merge-persons/merge-persons.mjs @@ -4,7 +4,7 @@ export default { key: "pipedrive-merge-persons", name: "Merge Persons", description: "Merge two persons in Pipedrive. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Persons#mergePersons)", - version: "0.0.4", + version: "0.0.5", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/remove-duplicate-notes/remove-duplicate-notes.mjs b/components/pipedrive/actions/remove-duplicate-notes/remove-duplicate-notes.mjs index da7ae9c5a2f9f..3d6277ac05bcd 100644 --- a/components/pipedrive/actions/remove-duplicate-notes/remove-duplicate-notes.mjs +++ b/components/pipedrive/actions/remove-duplicate-notes/remove-duplicate-notes.mjs @@ -5,7 +5,7 @@ export default { key: "pipedrive-remove-duplicate-notes", name: "Remove Duplicate Notes", description: "Remove duplicate notes from an object in Pipedrive. See the documentation for [getting notes](https://developers.pipedrive.com/docs/api/v1/Notes#getNotes) and [deleting notes](https://developers.pipedrive.com/docs/api/v1/Notes#deleteNote)", - version: "0.0.7", + version: "0.0.8", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/pipedrive/actions/search-leads/search-leads.mjs b/components/pipedrive/actions/search-leads/search-leads.mjs index b53144a04f0a1..0fcc723437d7c 100644 --- a/components/pipedrive/actions/search-leads/search-leads.mjs +++ b/components/pipedrive/actions/search-leads/search-leads.mjs @@ -5,7 +5,7 @@ export default { key: "pipedrive-search-leads", name: "Search Leads", description: "Search for leads by name or email. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Leads#searchLeads)", - version: "0.0.4", + version: "0.0.5", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/search-notes/search-notes.mjs b/components/pipedrive/actions/search-notes/search-notes.mjs index 8addb412ce9cf..9629981399f3f 100644 --- a/components/pipedrive/actions/search-notes/search-notes.mjs +++ b/components/pipedrive/actions/search-notes/search-notes.mjs @@ -4,7 +4,7 @@ export default { key: "pipedrive-search-notes", name: "Search Notes", description: "Search for notes in Pipedrive. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Notes#getNotes)", - version: "0.0.7", + version: "0.0.8", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/pipedrive/actions/search-persons/search-persons.mjs b/components/pipedrive/actions/search-persons/search-persons.mjs index 5c43846008586..1906e863c4b40 100644 --- a/components/pipedrive/actions/search-persons/search-persons.mjs +++ b/components/pipedrive/actions/search-persons/search-persons.mjs @@ -2,12 +2,13 @@ import { ConfigurationError } from "@pipedream/platform"; import constants from "../../common/constants.mjs"; import { parseObject } from "../../common/utils.mjs"; import pipedriveApp from "../../pipedrive.app.mjs"; +import { formatCustomFields } from "../../common/utils.mjs"; export default { key: "pipedrive-search-persons", name: "Search persons", description: "Searches all Persons by `name`, `email`, `phone`, `notes` and/or custom fields. This endpoint is a wrapper of `/v1/itemSearch` with a narrower OAuth scope. Found Persons can be filtered by Organization ID. See the Pipedrive API docs [here](https://developers.pipedrive.com/docs/api/v1/Persons#searchPersons)", - version: "0.1.16", + version: "0.1.17", annotations: { destructiveHint: false, openWorldHint: true, @@ -18,19 +19,19 @@ export default { pipedriveApp, term: { type: "string", - label: "Search term", + label: "Search Term", description: "The search term to look for. Minimum 2 characters (or 1 if using exact_match).", }, fields: { type: "string[]", - label: "Search fields", + label: "Search Fields", description: "An array containing fields to perform the search from. Defaults to all of them.", optional: true, options: constants.FIELD_OPTIONS, }, exactMatch: { type: "boolean", - label: "Exact match", + label: "Exact Match", description: "When enabled, only full exact matches against the given term are returned. It is not case sensitive.", optional: true, }, @@ -43,23 +44,29 @@ export default { }, includeFields: { type: "string", - label: "Include fields", + label: "Include Fields", description: "Supports including optional fields in the results which are not provided by default.", optional: true, options: constants.INCLUDE_FIELDS_OPTIONS, }, start: { type: "integer", - label: "Pagination start", + label: "Pagination Start", description: "Pagination start. Note that the pagination is based on main results and does not include related items when using `search_for_related_items` parameter.", optional: true, }, limit: { type: "integer", label: "Limit", - description: "Items shown per page.", + description: "Items shown per page", optional: true, }, + includeAllCustomFields: { + propDefinition: [ + pipedriveApp, + "includeAllCustomFields", + ], + }, }, async run({ $ }) { try { @@ -74,6 +81,19 @@ export default { limit: this.limit, }); + if (!resp?.data?.items?.length) { + $.export("$summary", "No persons found"); + return; + } + + if (this.includeAllCustomFields) { + resp.data.items = await formatCustomFields( + resp, + this.pipedriveApp.getPersons.bind(this), + this.pipedriveApp.getPersonCustomFields.bind(this), + ); + } + $.export("$summary", `Successfully found ${resp.data?.items.length || 0} persons`); return resp; diff --git a/components/pipedrive/actions/update-deal/update-deal.mjs b/components/pipedrive/actions/update-deal/update-deal.mjs index fdb422e85f374..97113268a2547 100644 --- a/components/pipedrive/actions/update-deal/update-deal.mjs +++ b/components/pipedrive/actions/update-deal/update-deal.mjs @@ -5,7 +5,7 @@ export default { key: "pipedrive-update-deal", name: "Update Deal", description: "Updates the properties of a deal. See the Pipedrive API docs for Deals [here](https://developers.pipedrive.com/docs/api/v1/Deals#updateDeal)", - version: "0.1.18", + version: "0.1.19", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/pipedrive/actions/update-person/update-person.mjs b/components/pipedrive/actions/update-person/update-person.mjs index ca6a079935070..05896d5ebe140 100644 --- a/components/pipedrive/actions/update-person/update-person.mjs +++ b/components/pipedrive/actions/update-person/update-person.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-update-person", name: "Update Person", description: "Updates an existing person in Pipedrive. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Persons#updatePerson)", - version: "0.0.8", + version: "0.0.9", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/pipedrive/common/utils.mjs b/components/pipedrive/common/utils.mjs index e382dc56a1b7d..963c93243e7e5 100644 --- a/components/pipedrive/common/utils.mjs +++ b/components/pipedrive/common/utils.mjs @@ -45,3 +45,48 @@ export const parseData = async ({ body.previous.custom_fields = await parseCustomFields(body.previous, customFields); return body; }; + +const getCustomFieldNames = async (fn) => { + const { data: personFields } = await fn(); + const customFields = personFields.filter((field) => field.created_by_user_id); + const customFieldNames = {}; + customFields.forEach((field) => { + customFieldNames[field.key] = field.name; + }); + return customFieldNames; +}; + +export const formatCustomFields = async (resp, getResourcesFn, getFieldsFn) => { + const { data: persons } = await getResourcesFn({ + ids: resp.data.items.map((item) => item.item.id), + }); + const customFieldNames = await getCustomFieldNames(getFieldsFn); + + return resp.data.items.map((person) => { + const { custom_fields: customFields } = persons.find((p) => p.id === person.item.id); + + if (!person.item?.custom_fields || Object.keys(customFields).length === 0) { + return person; + } + + if (!customFields || Object.keys(customFields).length === 0) { + return person; + } + const formattedCustomFields = {}; + Object.entries(customFields).forEach(([ + key, + value, + ]) => { + if (customFieldNames[key]) { + formattedCustomFields[customFieldNames[key]] = value; + } + }); + return { + ...person, + item: { + ...person.item, + custom_fields: formattedCustomFields, + }, + }; + }); +}; diff --git a/components/pipedrive/package.json b/components/pipedrive/package.json index f564d08b23cc2..c347593ae8572 100644 --- a/components/pipedrive/package.json +++ b/components/pipedrive/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/pipedrive", - "version": "0.10.3", + "version": "0.10.4", "description": "Pipedream Pipedrive Components", "main": "pipedrive.app.mjs", "keywords": [ diff --git a/components/pipedrive/pipedrive.app.mjs b/components/pipedrive/pipedrive.app.mjs index 622a4ef38e537..cc42263290ab0 100644 --- a/components/pipedrive/pipedrive.app.mjs +++ b/components/pipedrive/pipedrive.app.mjs @@ -370,6 +370,12 @@ export default { })) || []; }, }, + includeAllCustomFields: { + type: "boolean", + label: "Include All Custom Fields", + description: "When enabled, all custom fields will be included in the results", + optional: true, + }, }, methods: { api(model, version = "v1") { @@ -480,7 +486,7 @@ export default { }); }, searchPersons(opts = {}) { - const personsApi = this.api("PersonsApi"); + const personsApi = this.api("PersonsApi", "v2"); return personsApi.searchPersons(opts); }, updateDeal({ diff --git a/components/pipedrive/sources/new-deal-instant/new-deal-instant.mjs b/components/pipedrive/sources/new-deal-instant/new-deal-instant.mjs index dfc87a1d2a3ab..06f1d06b534f0 100644 --- a/components/pipedrive/sources/new-deal-instant/new-deal-instant.mjs +++ b/components/pipedrive/sources/new-deal-instant/new-deal-instant.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-new-deal-instant", name: "New Deal (Instant)", description: "Emit new event when a new deal is created.", - version: "0.0.12", + version: "0.0.13", type: "source", dedupe: "unique", methods: { diff --git a/components/pipedrive/sources/new-event-instant/new-event-instant.mjs b/components/pipedrive/sources/new-event-instant/new-event-instant.mjs index cf85df502e321..d262b798db3d4 100644 --- a/components/pipedrive/sources/new-event-instant/new-event-instant.mjs +++ b/components/pipedrive/sources/new-event-instant/new-event-instant.mjs @@ -5,7 +5,7 @@ export default { key: "pipedrive-new-event-instant", name: "New Event (Instant)", description: "Emit new event when a new webhook event is received. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Webhooks#addWebhook)", - version: "0.0.3", + version: "0.0.4", type: "source", dedupe: "unique", props: { diff --git a/components/pipedrive/sources/new-person-instant/new-person-instant.mjs b/components/pipedrive/sources/new-person-instant/new-person-instant.mjs index 33f4d0713d0cb..fa837ea7bf78a 100644 --- a/components/pipedrive/sources/new-person-instant/new-person-instant.mjs +++ b/components/pipedrive/sources/new-person-instant/new-person-instant.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-new-person-instant", name: "New Person (Instant)", description: "Emit new event when a new person is created.", - version: "0.0.12", + version: "0.0.13", type: "source", dedupe: "unique", methods: { diff --git a/components/pipedrive/sources/updated-deal-instant/updated-deal-instant.mjs b/components/pipedrive/sources/updated-deal-instant/updated-deal-instant.mjs index 9e394366f74e0..8e3976ed1ddfb 100644 --- a/components/pipedrive/sources/updated-deal-instant/updated-deal-instant.mjs +++ b/components/pipedrive/sources/updated-deal-instant/updated-deal-instant.mjs @@ -7,7 +7,7 @@ export default { key: "pipedrive-updated-deal-instant", name: "Deal Updated (Instant)", description: "Emit new event when a deal is updated.", - version: "0.1.5", + version: "0.1.6", type: "source", dedupe: "unique", methods: { diff --git a/components/pipedrive/sources/updated-lead-instant/updated-lead-instant.mjs b/components/pipedrive/sources/updated-lead-instant/updated-lead-instant.mjs index 5a83bf19aafdb..60618a73c521b 100644 --- a/components/pipedrive/sources/updated-lead-instant/updated-lead-instant.mjs +++ b/components/pipedrive/sources/updated-lead-instant/updated-lead-instant.mjs @@ -7,7 +7,7 @@ export default { key: "pipedrive-updated-lead-instant", name: "Lead Updated (Instant)", description: "Emit new event when a lead is updated.", - version: "0.1.5", + version: "0.1.6", type: "source", dedupe: "unique", methods: { diff --git a/components/pipedrive/sources/updated-person-instant/updated-person-instant.mjs b/components/pipedrive/sources/updated-person-instant/updated-person-instant.mjs index a22c4cb4923fb..c55819bd77518 100644 --- a/components/pipedrive/sources/updated-person-instant/updated-person-instant.mjs +++ b/components/pipedrive/sources/updated-person-instant/updated-person-instant.mjs @@ -7,7 +7,7 @@ export default { key: "pipedrive-updated-person-instant", name: "Person Updated (Instant)", description: "Emit new event when a person is updated.", - version: "0.1.5", + version: "0.1.6", type: "source", dedupe: "unique", methods: {