Skip to content

Commit 90f2b52

Browse files
authored
New Components - hubspot (#17940)
* new components * pnpm-lock.yaml * pnpm-lock.yaml * pnpm-lock.yaml * updates * pnpm-lock.yaml
1 parent 1e68cd3 commit 90f2b52

File tree

5 files changed

+170
-1
lines changed

5 files changed

+170
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
import { API_PATH } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
import { ConfigurationError } from "@pipedream/platform";
5+
6+
export default {
7+
key: "hubspot-batch-create-companies",
8+
name: "Batch Create Companies",
9+
description: "Create a batch of companies in Hubspot. [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/objects/companies#post-%2Fcrm%2Fv3%2Fobjects%2Fcompanies%2Fbatch%2Fcreate)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
hubspot,
14+
inputs: {
15+
type: "string[]",
16+
label: "Inputs (Companies)",
17+
description: "Provide a **list of companies** to be created. [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/objects/companies#post-%2Fcrm%2Fv3%2Fobjects%2Fcompanies%2Fbatch%2Fcreate) for more information. Example: `[ { \"properties\": { \"name\": \"CompanyName\"} } ]`",
18+
},
19+
},
20+
methods: {
21+
batchCreateCompanies(opts = {}) {
22+
return this.hubspot.makeRequest({
23+
api: API_PATH.CRMV3,
24+
endpoint: "/objects/companies/batch/create",
25+
method: "POST",
26+
...opts,
27+
});
28+
},
29+
},
30+
async run({ $ }) {
31+
try {
32+
const response = await this.batchCreateCompanies({
33+
$,
34+
data: {
35+
inputs: parseObject(this.inputs),
36+
},
37+
});
38+
$.export("$summary", `Created ${response.results.length} compan${response.results.length === 1
39+
? "y"
40+
: "ies"}`);
41+
return response;
42+
} catch (error) {
43+
const message = JSON.parse((JSON.parse(error.message).message).split(/:(.+)/)[1])[0].message;
44+
throw new ConfigurationError(message.split(/:(.+)/)[0]);
45+
}
46+
},
47+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
import { API_PATH } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
import { ConfigurationError } from "@pipedream/platform";
5+
6+
export default {
7+
key: "hubspot-batch-update-companies",
8+
name: "Batch Update Companies",
9+
description: "Update a batch of companies in Hubspot. [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/objects/companies#post-%2Fcrm%2Fv3%2Fobjects%2Fcompanies%2Fbatch%2Fupdate)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
hubspot,
14+
inputs: {
15+
type: "string[]",
16+
label: "Inputs (Companies)",
17+
description: "Provide a **list of companies** to be updated. [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/objects/companies#post-%2Fcrm%2Fv3%2Fobjects%2Fcompanies%2Fbatch%2Fupdate) for more information. Example: `[ { \"id\": \"123\", \"properties\": { \"name\": \"CompanyName\"} } ]`",
18+
},
19+
},
20+
methods: {
21+
batchUpdateCompanies(opts = {}) {
22+
return this.hubspot.makeRequest({
23+
api: API_PATH.CRMV3,
24+
endpoint: "/objects/companies/batch/update",
25+
method: "POST",
26+
...opts,
27+
});
28+
},
29+
},
30+
async run({ $ }) {
31+
try {
32+
const response = await this.batchUpdateCompanies({
33+
$,
34+
data: {
35+
inputs: parseObject(this.inputs),
36+
},
37+
});
38+
$.export("$summary", `Updated ${response.results.length} compan${response.results.length === 1
39+
? "y"
40+
: "ies"}`);
41+
return response;
42+
} catch (error) {
43+
const message = JSON.parse((JSON.parse(error.message).message).split(/:(.+)/)[1])[0].message;
44+
throw new ConfigurationError(message.split(/:(.+)/)[0]);
45+
}
46+
},
47+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
import { API_PATH } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
import { ConfigurationError } from "@pipedream/platform";
5+
6+
export default {
7+
key: "hubspot-batch-upsert-companies",
8+
name: "Batch Upsert Companies",
9+
description: "Upsert a batch of companies in Hubspot. [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/objects/companies#post-%2Fcrm%2Fv3%2Fobjects%2Fcompanies%2Fbatch%2Fupsert)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
hubspot,
14+
infoAlert: {
15+
type: "alert",
16+
alertType: "info",
17+
content: "Create or update companies identified by a unique property value as specified by the `idProperty` query parameter. `idProperty` query param refers to a property whose values are unique for the object. To manage properties in Hubspot, navigate to your Settings -> Data Management -> Properties.",
18+
},
19+
inputs: {
20+
type: "string[]",
21+
label: "Inputs (Companies)",
22+
description: "Provide a **list of companies** to be upserted. [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/objects/companies#post-%2Fcrm%2Fv3%2Fobjects%2Fcompanies%2Fbatch%2Fupsert) for more information. Example: `[ { \"idProperty\": \"unique_property\", \"id\": \"123\", \"properties\": { \"name\": \"CompanyName\" } } ]`",
23+
},
24+
},
25+
methods: {
26+
batchUpsertCompanies(opts = {}) {
27+
return this.hubspot.makeRequest({
28+
api: API_PATH.CRMV3,
29+
endpoint: "/objects/companies/batch/upsert",
30+
method: "POST",
31+
...opts,
32+
});
33+
},
34+
},
35+
async run({ $ }) {
36+
try {
37+
const response = await this.batchUpsertCompanies({
38+
$,
39+
data: {
40+
inputs: parseObject(this.inputs),
41+
},
42+
});
43+
$.export("$summary", `Upserted ${response.results.length} companies`);
44+
return response;
45+
} catch (error) {
46+
const message = JSON.parse((JSON.parse(error.message).message).split(/:(.+)/)[1])[0].message;
47+
throw new ConfigurationError(message.split(/:(.+)/)[0]);
48+
}
49+
},
50+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) {
3+
return undefined;
4+
}
5+
if (typeof obj === "string") {
6+
try {
7+
return JSON.parse(obj);
8+
} catch (e) {
9+
return obj;
10+
}
11+
}
12+
if (Array.isArray(obj)) {
13+
return obj.map(parseObject);
14+
}
15+
if (typeof obj === "object") {
16+
return Object.fromEntries(Object.entries(obj).map(([
17+
key,
18+
value,
19+
]) => [
20+
key,
21+
parseObject(value),
22+
]));
23+
}
24+
return obj;
25+
};

components/hubspot/package.json

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

0 commit comments

Comments
 (0)