Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions components/hubspot/actions/search-crm/search-crm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import {
DEFAULT_CONTACT_PROPERTIES,
DEFAULT_DEAL_PROPERTIES,
DEFAULT_LEAD_PROPERTIES,
DEFAULT_LIMIT,
DEFAULT_LINE_ITEM_PROPERTIES,
DEFAULT_PRODUCT_PROPERTIES,
DEFAULT_TICKET_PROPERTIES,
SEARCHABLE_OBJECT_TYPES,
} from "../../common/constants.mjs";
import hubspot from "../../hubspot.app.mjs";
import common from "../common/common-create.mjs";
const DEFAULT_LIMIT = 200;

export default {
key: "hubspot-search-crm",
name: "Search CRM",
description:
"Search companies, contacts, deals, feedback submissions, products, tickets, line-items, quotes, leads, or custom objects. [See the documentation](https://developers.hubspot.com/docs/api/crm/search)",
version: "1.0.12",
version: "1.1.0",
type: "action",
props: {
hubspot,
Expand Down Expand Up @@ -52,6 +52,13 @@ export default {
optional: true,
reloadProps: true,
},
offset: {
type: "integer",
label: "Offset",
description: "The offset to start from. Used for pagination.",
default: 0,
optional: true,
},
},
async additionalProps() {
const props = {};
Expand Down Expand Up @@ -224,23 +231,6 @@ export default {
})) || []
);
},
async paginate(params) {
let results;
const items = [];
while (!results || params.after) {
results = await this.hubspot.searchCRM(params);
if (results.paging) {
params.after = results.paging.next.after;
} else {
delete params.after;
}
results = results.results;
for (const result of results) {
items.push(result);
}
}
return items;
},
},
async run({ $ }) {
const {
Expand All @@ -251,6 +241,7 @@ export default {
searchProperty,
searchValue,
exactMatch,
offset,
/* eslint-disable no-unused-vars */
info,
createIfNotFound,
Expand Down Expand Up @@ -282,8 +273,18 @@ export default {
properties: [
...defaultProperties,
...additionalProperties,
searchProperty,
],
sorts: [
{
propertyName: "createdate",
direction: "DESCENDING",
},
],
limit: DEFAULT_LIMIT,
after: offset,
};

if (exactMatch) {
data.filters = [
{
Expand All @@ -292,17 +293,17 @@ export default {
value: searchValue,
},
];
} else {
data.limit = DEFAULT_LIMIT;
}

let results = await this.paginate({
let {
results, paging,
} = await this.hubspot.searchCRM({
object: actualObjectType,
data,
});

if (!exactMatch) {
results = results.filter(
results = results?.filter(
(result) =>
result.properties[searchProperty] &&
result.properties[searchProperty]
Expand All @@ -328,6 +329,9 @@ export default {
"$summary",
`Successfully retrieved ${results?.length} object(s).`,
);
return results;
return {
results,
paging,
};
},
};
2 changes: 1 addition & 1 deletion components/hubspot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/hubspot",
"version": "1.7.4",
"version": "1.7.5",
"description": "Pipedream Hubspot Components",
"main": "hubspot.app.mjs",
"keywords": [
Expand Down
Loading