From 12a5f75654060722bd192a0b6b13e215553d5163 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 22 May 2025 13:14:06 -0400 Subject: [PATCH] add-lead --- .../actions/add-activity/add-activity.mjs | 2 +- .../pipedrive/actions/add-deal/add-deal.mjs | 2 +- .../pipedrive/actions/add-lead/add-lead.mjs | 107 ++++++++++++++++++ .../pipedrive/actions/add-note/add-note.mjs | 2 +- .../add-organization/add-organization.mjs | 2 +- .../actions/add-person/add-person.mjs | 2 +- .../actions/search-persons/search-persons.mjs | 2 +- .../actions/update-deal/update-deal.mjs | 2 +- components/pipedrive/package.json | 2 +- components/pipedrive/pipedrive.app.mjs | 26 +++++ .../new-deal-instant/new-deal-instant.mjs | 2 +- .../new-person-instant/new-person-instant.mjs | 2 +- .../updated-deal-instant.mjs | 2 +- .../updated-person-instant.mjs | 2 +- 14 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 components/pipedrive/actions/add-lead/add-lead.mjs diff --git a/components/pipedrive/actions/add-activity/add-activity.mjs b/components/pipedrive/actions/add-activity/add-activity.mjs index d611e311fce78..97487eb410647 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.7", + version: "0.1.8", type: "action", props: { pipedriveApp, diff --git a/components/pipedrive/actions/add-deal/add-deal.mjs b/components/pipedrive/actions/add-deal/add-deal.mjs index aa309c5c8a6e0..a4261c16ac922 100644 --- a/components/pipedrive/actions/add-deal/add-deal.mjs +++ b/components/pipedrive/actions/add-deal/add-deal.mjs @@ -5,7 +5,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.7", + version: "0.1.8", type: "action", props: { pipedriveApp, diff --git a/components/pipedrive/actions/add-lead/add-lead.mjs b/components/pipedrive/actions/add-lead/add-lead.mjs new file mode 100644 index 0000000000000..0a15c2a577a23 --- /dev/null +++ b/components/pipedrive/actions/add-lead/add-lead.mjs @@ -0,0 +1,107 @@ +import pipedrive from "../../pipedrive.app.mjs"; +import { ConfigurationError } from "@pipedream/platform"; +import { parseObject } from "../../common/utils.mjs"; + +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.1", + type: "action", + props: { + pipedrive, + title: { + type: "string", + label: "Title", + description: "The name of the lead", + }, + personId: { + propDefinition: [ + pipedrive, + "personId", + ], + description: "The ID of a person which this lead will be linked to. If the person does not exist yet, it needs to be created first. This property is required unless organization_id is specified.", + }, + organizationId: { + propDefinition: [ + pipedrive, + "organizationId", + ], + description: "The ID of an organization which this lead will be linked to. If the organization does not exist yet, it needs to be created first. This property is required unless person_id is specified.", + }, + ownerId: { + propDefinition: [ + pipedrive, + "userId", + ], + description: "The ID of the user which will be the owner of the created lead. If not provided, the user making the request will be used.", + }, + leadLabelIds: { + propDefinition: [ + pipedrive, + "leadLabelIds", + ], + }, + value: { + type: "object", + label: "Value", + description: "Potential value of the lead, e.g. `{ \"amount\": 200, \"currency\": \"EUR\" }`", + optional: true, + }, + expectedCloseDate: { + type: "string", + label: "Expected Close Date", + description: "The date of when the deal which will be created from the lead is expected to be closed. In ISO 8601 format: YYYY-MM-DD.", + optional: true, + }, + visibleTo: { + type: "string", + label: "Visible To", + description: "The visibility of the lead. If omitted, the visibility will be set to the default visibility setting of this item type for the authorized user. Read more about visibility groups [here](https://support.pipedrive.com/en/article/visibility-groups).", + options: [ + { + label: "Essential / Advanced plan - Owner & followers, Professional / Enterprise plan - Owner only", + value: "1", + }, + { + label: "Essential / Advanced plan - Entire company, Professional / Enterprise plan - Owner's visibility group", + value: "3", + }, + { + label: "Professional / Enterprise plan - Owner's visibility group and sub-groups", + value: "5", + }, + { + label: "Professional / Enterprise plan - Entire company", + value: "7", + }, + ], + optional: true, + }, + wasSeen: { + type: "boolean", + label: "Was Seen", + description: "A flag indicating whether the lead was seen by someone in the Pipedrive UI", + optional: true, + }, + }, + async run({ $ }) { + if (!this.organizationId && !this.personId) { + throw new ConfigurationError("Either organizationId or personId is required"); + } + + const response = await this.pipedrive.addLead({ + title: this.title, + person_id: this.personId, + organization_id: this.organizationId, + owner_id: this.ownerId, + label_ids: this.leadLabelIds, + value: parseObject(this.value), + expected_close_date: this.expectedCloseDate, + visible_to: this.visibleTo, + was_seen: this.wasSeen, + }); + $.export("$summary", `Successfully created lead: ${response.data?.title || response.data?.id}`); + return response; + }, +}; diff --git a/components/pipedrive/actions/add-note/add-note.mjs b/components/pipedrive/actions/add-note/add-note.mjs index 1d75bbaccc846..cdd033ccb58b2 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.5", + version: "0.0.6", type: "action", props: { pipedriveApp, diff --git a/components/pipedrive/actions/add-organization/add-organization.mjs b/components/pipedrive/actions/add-organization/add-organization.mjs index e2775daa867a5..1972ea0278475 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.7", + version: "0.1.8", type: "action", props: { pipedriveApp, diff --git a/components/pipedrive/actions/add-person/add-person.mjs b/components/pipedrive/actions/add-person/add-person.mjs index e14be3b0aff84..f3603ba6099b9 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.7", + version: "0.1.8", type: "action", props: { pipedriveApp, diff --git a/components/pipedrive/actions/search-persons/search-persons.mjs b/components/pipedrive/actions/search-persons/search-persons.mjs index 459c87f16ac45..2c12eea9238ce 100644 --- a/components/pipedrive/actions/search-persons/search-persons.mjs +++ b/components/pipedrive/actions/search-persons/search-persons.mjs @@ -7,7 +7,7 @@ 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.7", + version: "0.1.8", type: "action", props: { pipedriveApp, diff --git a/components/pipedrive/actions/update-deal/update-deal.mjs b/components/pipedrive/actions/update-deal/update-deal.mjs index af698080f1aeb..ad537f01d00a0 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.8", + version: "0.1.9", type: "action", props: { pipedriveApp, diff --git a/components/pipedrive/package.json b/components/pipedrive/package.json index 70b9227a03442..6c7da0107bfd0 100644 --- a/components/pipedrive/package.json +++ b/components/pipedrive/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/pipedrive", - "version": "0.3.13", + "version": "0.4.0", "description": "Pipedream Pipedrive Components", "main": "pipedrive.app.mjs", "keywords": [ diff --git a/components/pipedrive/pipedrive.app.mjs b/components/pipedrive/pipedrive.app.mjs index 51a85b4acc6ea..043cbf37edbae 100644 --- a/components/pipedrive/pipedrive.app.mjs +++ b/components/pipedrive/pipedrive.app.mjs @@ -278,6 +278,22 @@ export default { }; }, }, + leadLabelIds: { + type: "string[]", + label: "Lead Label IDs", + description: "The IDs of the lead labels to associate with the lead", + optional: true, + async options() { + const { data: leadLabels } = await this.getLeadLabels(); + + return leadLabels?.map(({ + id, name, + }) => ({ + label: name, + value: id, + })); + }, + }, }, methods: { api(model, version = "v1") { @@ -323,6 +339,10 @@ export default { const stagesApi = this.api("StagesApi", "v2"); return stagesApi.getStages(opts); }, + getLeadLabels(opts) { + const leadLabelsApi = this.api("LeadLabelsApi"); + return leadLabelsApi.getLeadLabels(opts); + }, addActivity(opts = {}) { const activityApi = this.api("ActivitiesApi", "v2"); return activityApi.addActivity({ @@ -353,6 +373,12 @@ export default { AddPersonRequest: opts, }); }, + addLead(opts = {}) { + const leadApi = this.api("LeadsApi"); + return leadApi.addLead({ + AddLeadRequest: opts, + }); + }, addWebhook(opts = {}) { const webhooksApi = this.api("WebhooksApi"); return webhooksApi.addWebhook({ 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 c9b209e44eaf3..bbceb7e1506b8 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.3", + version: "0.0.4", type: "source", dedupe: "unique", methods: { 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 e266beb0a92e2..442a82d6400c3 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.3", + version: "0.0.4", 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 f0a2b0ec993c6..d294f75de3622 100644 --- a/components/pipedrive/sources/updated-deal-instant/updated-deal-instant.mjs +++ b/components/pipedrive/sources/updated-deal-instant/updated-deal-instant.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-updated-deal-instant", name: "New Deal Update (Instant)", description: "Emit new event when a deal is updated.", - version: "0.0.3", + version: "0.0.4", 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 14346822f2fc5..49f2e7a4d1f16 100644 --- a/components/pipedrive/sources/updated-person-instant/updated-person-instant.mjs +++ b/components/pipedrive/sources/updated-person-instant/updated-person-instant.mjs @@ -6,7 +6,7 @@ export default { key: "pipedrive-updated-person-instant", name: "Updated Person (Instant)", description: "Emit new event when a person is updated.", - version: "0.0.3", + version: "0.0.4", type: "source", dedupe: "unique", methods: {