Skip to content

Commit 4ccb465

Browse files
committed
[ACTION] Pipedrive - Get All Leads
1 parent e26745a commit 4ccb465

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import app from "../../pipedrive.app.mjs";
2+
3+
export default {
4+
key: "pipedrive-get-all-leads",
5+
name: "Get All Leads",
6+
description: "Get all leads from Pipedrive. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Leads#getLeads)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
maxResults: {
17+
type: "integer",
18+
label: "Max Results",
19+
description: "The maximum number of results to return. If not provided, all leads will be returned.",
20+
optional: true,
21+
},
22+
ownerId: {
23+
label: "Owner ID",
24+
description: "If supplied, only leads matching the given user will be returned. However, **Filter ID** takes precedence over **Owner ID** when supplied.",
25+
propDefinition: [
26+
app,
27+
"userId",
28+
],
29+
},
30+
personId: {
31+
propDefinition: [
32+
app,
33+
"personId",
34+
],
35+
description: "If supplied, only leads matching the given person will be returned. However, **Filter ID** takes precedence over **Person ID** when supplied.",
36+
optional: true,
37+
},
38+
organizationId: {
39+
propDefinition: [
40+
app,
41+
"organizationId",
42+
],
43+
description: "If supplied, only leads matching the given organization will be returned. However, **Filter ID** takes precedence over **Organization ID** when supplied.",
44+
optional: true,
45+
},
46+
filterId: {
47+
propDefinition: [
48+
app,
49+
"filterId",
50+
],
51+
description: "The ID of the filter to use. Takes precedence over **Owner ID**, **Person ID**, and **Organization ID** when supplied.",
52+
},
53+
sort: {
54+
type: "string",
55+
label: "Sort",
56+
description: "The field names and sorting mode separated by a comma (`field_name_1 ASC, field_name_2 DESC`). Only first-level field keys are supported (no nested keys). Valid fields: `id, title, owner_id, creator_id, was_seen, expected_close_date, next_activity_id, add_time, update_time`",
57+
optional: true,
58+
},
59+
},
60+
async run({ $ }) {
61+
const {
62+
app,
63+
maxResults,
64+
ownerId,
65+
personId,
66+
organizationId,
67+
filterId,
68+
sort,
69+
} = this;
70+
71+
const leads = await app.getPaginatedResources({
72+
fn: app.getLeads,
73+
params: {
74+
...(ownerId && {
75+
owner_id: ownerId,
76+
}),
77+
...(personId && {
78+
person_id: personId,
79+
}),
80+
...(organizationId && {
81+
organization_id: organizationId,
82+
}),
83+
...(filterId && {
84+
filter_id: filterId,
85+
}),
86+
...(sort && {
87+
sort: sort,
88+
}),
89+
},
90+
max: maxResults,
91+
});
92+
93+
$.export("$summary", `Successfully retrieved ${leads.length} lead${leads.length === 1
94+
? ""
95+
: "s"}`);
96+
return leads;
97+
},
98+
};

components/pipedrive/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/pipedrive",
3-
"version": "0.10.5",
3+
"version": "0.10.6",
44
"description": "Pipedream Pipedrive Components",
55
"main": "pipedrive.app.mjs",
66
"keywords": [

components/pipedrive/pipedrive.app.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,24 @@ export default {
294294
}));
295295
},
296296
},
297+
filterId: {
298+
type: "integer",
299+
label: "Lead Filter ID",
300+
description: "The ID of a filter to apply to leads",
301+
optional: true,
302+
async options({ filterType = "leads" }) {
303+
const { data: filters } = await this.getFilters({
304+
type: filterType,
305+
});
306+
307+
return filters?.map(({
308+
id, name,
309+
}) => ({
310+
label: name,
311+
value: id,
312+
}));
313+
},
314+
},
297315
emails: {
298316
type: "string[]",
299317
label: "Emails",
@@ -425,6 +443,10 @@ export default {
425443
const leadLabelsApi = this.api("LeadLabelsApi");
426444
return leadLabelsApi.getLeadLabels(opts);
427445
},
446+
getFilters(opts = {}) {
447+
const filtersApi = this.api("FiltersApi");
448+
return filtersApi.getFilters(opts);
449+
},
428450
getNotes(opts = {}) {
429451
const notesApi = this.api("NotesApi");
430452
return notesApi.getNotes(opts);

0 commit comments

Comments
 (0)