Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import hubspot from "../../hubspot.app.mjs";
import { API_PATH } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "hubspot-batch-create-companies",
name: "Batch Create Companies",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
inputs: {
type: "string[]",
label: "Inputs (Companies)",
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\"} } ]`",
},
},
methods: {
batchCreateCompanies(opts = {}) {
return this.hubspot.makeRequest({
api: API_PATH.CRMV3,
endpoint: "/objects/companies/batch/create",
method: "POST",
...opts,
});
},
},
async run({ $ }) {
try {
const response = await this.batchCreateCompanies({
$,
data: {
inputs: parseObject(this.inputs),
},
});
$.export("$summary", `Created ${response.results.length} compan${response.results.length === 1
? "y"
: "ies"}`);
return response;
} catch (error) {
const message = JSON.parse((JSON.parse(error.message).message).split(/:(.+)/)[1])[0].message;
throw new ConfigurationError(message.split(/:(.+)/)[0]);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import hubspot from "../../hubspot.app.mjs";
import { API_PATH } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "hubspot-batch-update-companies",
name: "Batch Update Companies",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
inputs: {
type: "string[]",
label: "Inputs (Companies)",
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\"} } ]`",
},
},
methods: {
batchUpdateCompanies(opts = {}) {
return this.hubspot.makeRequest({
api: API_PATH.CRMV3,
endpoint: "/objects/companies/batch/update",
method: "POST",
...opts,
});
},
},
async run({ $ }) {
try {
const response = await this.batchUpdateCompanies({
$,
data: {
inputs: parseObject(this.inputs),
},
});
$.export("$summary", `Updated ${response.results.length} compan${response.results.length === 1
? "y"
: "ies"}`);
return response;
} catch (error) {
const message = JSON.parse((JSON.parse(error.message).message).split(/:(.+)/)[1])[0].message;
throw new ConfigurationError(message.split(/:(.+)/)[0]);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import hubspot from "../../hubspot.app.mjs";
import { API_PATH } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "hubspot-batch-upsert-companies",
name: "Batch Upsert Companies",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
infoAlert: {
type: "alert",
alertType: "info",
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.",
},
inputs: {
type: "string[]",
label: "Inputs (Companies)",
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\" } } ]`",
},
},
methods: {
batchUpsertCompanies(opts = {}) {
return this.hubspot.makeRequest({
api: API_PATH.CRMV3,
endpoint: "/objects/companies/batch/upsert",
method: "POST",
...opts,
});
},
},
async run({ $ }) {
try {
const response = await this.batchUpsertCompanies({
$,
data: {
inputs: parseObject(this.inputs),
},
});
$.export("$summary", `Upserted ${response.results.length} companies`);
return response;
} catch (error) {
const message = JSON.parse((JSON.parse(error.message).message).split(/:(.+)/)[1])[0].message;
throw new ConfigurationError(message.split(/:(.+)/)[0]);
}
},
};
25 changes: 25 additions & 0 deletions components/hubspot/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const parseObject = (obj) => {
if (!obj) {
return undefined;
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
if (Array.isArray(obj)) {
return obj.map(parseObject);
}
if (typeof obj === "object") {
return Object.fromEntries(Object.entries(obj).map(([
key,
value,
]) => [
key,
parseObject(value),
]));
}
return obj;
};
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.3.0",
"version": "1.4.0",
"description": "Pipedream Hubspot Components",
"main": "hubspot.app.mjs",
"keywords": [
Expand Down
5 changes: 3 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.