|
| 1 | +import pipedriveApp from "../../pipedrive.app.mjs"; |
| 2 | +import constants from "../../common/constants.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "pipedrive-search-leads", |
| 6 | + name: "Search Leads", |
| 7 | + description: "Search for leads by name or email. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Leads#searchLeads)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + pipedriveApp, |
| 12 | + term: { |
| 13 | + type: "string", |
| 14 | + label: "Search Term", |
| 15 | + description: "The search term to look for. Minimum 2 characters (or 1 if using exact_match).", |
| 16 | + }, |
| 17 | + exactMatch: { |
| 18 | + type: "boolean", |
| 19 | + label: "Exact Match", |
| 20 | + description: "When enabled, only full exact matches against the given term are returned. It is not case sensitive.", |
| 21 | + optional: true, |
| 22 | + }, |
| 23 | + fields: { |
| 24 | + type: "string[]", |
| 25 | + label: "Search Fields", |
| 26 | + description: "An array containing fields to perform the search from. Defaults to all of them.", |
| 27 | + optional: true, |
| 28 | + options: constants.LEAD_FIELD_OPTIONS, |
| 29 | + }, |
| 30 | + personId: { |
| 31 | + propDefinition: [ |
| 32 | + pipedriveApp, |
| 33 | + "personId", |
| 34 | + ], |
| 35 | + description: "Will filter leads by the provided Person ID", |
| 36 | + }, |
| 37 | + organizationId: { |
| 38 | + propDefinition: [ |
| 39 | + pipedriveApp, |
| 40 | + "organizationId", |
| 41 | + ], |
| 42 | + description: "Will filter leads by the provided Organization ID", |
| 43 | + }, |
| 44 | + includeFields: { |
| 45 | + type: "string", |
| 46 | + label: "Include fields", |
| 47 | + description: "Supports including optional fields in the results which are not provided by default.", |
| 48 | + optional: true, |
| 49 | + options: [ |
| 50 | + "lead.was_seen", |
| 51 | + ], |
| 52 | + }, |
| 53 | + }, |
| 54 | + async run({ $ }) { |
| 55 | + const { data: { items = [] } } = await this.pipedriveApp.searchLeads({ |
| 56 | + term: this.term, |
| 57 | + exact_match: this.exactMatch, |
| 58 | + fields: this.fields, |
| 59 | + person_id: this.personId, |
| 60 | + organization_id: this.organizationId, |
| 61 | + include_fields: this.includeFields, |
| 62 | + }); |
| 63 | + $.export("$summary", `Successfully found ${items.length} lead${items.length === 1 |
| 64 | + ? "" |
| 65 | + : "s"}`); |
| 66 | + return items; |
| 67 | + }, |
| 68 | +}; |
0 commit comments